def __call__(self, environ, start_response): path = environ["PATH_INFO"] dav_res = None if environ["wsgidav.provider"]: dav_res = environ["wsgidav.provider"].get_resource_inst(path, environ) if ( environ["REQUEST_METHOD"] in ("GET", "HEAD") and dav_res and dav_res.is_collection ): if util.get_content_length(environ) != 0: self._fail( HTTP_MEDIATYPE_NOT_SUPPORTED, "The server does not handle any body content.", ) if environ["REQUEST_METHOD"] == "HEAD": return util.send_status_response( environ, start_response, HTTP_OK, is_head=True ) # Support DAV mount (http://www.ietf.org/rfc/rfc4709.txt) if self.dir_config.get("davmount") and "davmount" in environ.get( "QUERY_STRING", "" ): collectionUrl = util.make_complete_url(environ) collectionUrl = collectionUrl.split("?", 1)[0] res = compat.to_bytes(DAVMOUNT_TEMPLATE.format(collectionUrl)) # TODO: support <dm:open>%s</dm:open> start_response( "200 OK", [ ("Content-Type", "application/davmount+xml"), ("Content-Length", str(len(res))), ("Cache-Control", "private"), ("Date", util.get_rfc1123_time()), ], ) return [res] context = self._get_context(environ, dav_res) res = self.template.render(**context) res = compat.to_bytes(res) start_response( "200 OK", [ ("Content-Type", "text/html"), ("Content-Length", str(len(res))), ("Cache-Control", "private"), ("Date", util.get_rfc1123_time()), ], ) return [res] return self.next_app(environ, start_response)