Set Content-Length for HEAD requests
This commit is contained in:
parent
b93842b10c
commit
4a0bcde7a3
@ -121,6 +121,9 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
|
||||
|
||||
def _handle_request(self, environ: types.WSGIEnviron
|
||||
) -> _IntermediateResponse:
|
||||
time_begin = datetime.datetime.now()
|
||||
request_method = environ["REQUEST_METHOD"].upper()
|
||||
|
||||
"""Manage a request."""
|
||||
def response(status: int, headers: types.WSGIResponseHeaders,
|
||||
answer: Union[None, str, bytes]) -> _IntermediateResponse:
|
||||
@ -144,7 +147,8 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
|
||||
headers["Content-Encoding"] = "gzip"
|
||||
|
||||
headers["Content-Length"] = str(len(answer))
|
||||
answers.append(answer)
|
||||
if request_method != "HEAD":
|
||||
answers.append(answer)
|
||||
|
||||
# Add extra headers set in configuration
|
||||
headers.update(self._extra_headers)
|
||||
@ -161,8 +165,6 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
|
||||
# Return response content
|
||||
return status_text, list(headers.items()), answers
|
||||
|
||||
time_begin = datetime.datetime.now()
|
||||
request_method = environ["REQUEST_METHOD"].upper()
|
||||
unsafe_path = environ.get("PATH_INFO", "")
|
||||
remote_host = "unknown"
|
||||
if environ.get("REMOTE_HOST"):
|
||||
|
@ -27,5 +27,4 @@ class ApplicationPartHead(ApplicationPartGet, ApplicationBase):
|
||||
def do_HEAD(self, environ: types.WSGIEnviron, base_prefix: str, path: str,
|
||||
user: str) -> types.WSGIResponse:
|
||||
"""Manage HEAD request."""
|
||||
status, headers, _ = self.do_GET(environ, base_prefix, path, user)
|
||||
return status, headers, None
|
||||
return self.do_GET(environ, base_prefix, path, user)
|
||||
|
@ -382,8 +382,9 @@ permissions: RrWw""")
|
||||
assert xml.find(xmlutils.make_clark("C:no-uid-conflict")) is not None
|
||||
|
||||
def test_head(self) -> None:
|
||||
status, _, _ = self.request("HEAD", "/")
|
||||
status, headers, answer = self.request("HEAD", "/")
|
||||
assert status == 302
|
||||
assert int(headers.get("Content-Length", "0")) > 0 and not answer
|
||||
|
||||
def test_options(self) -> None:
|
||||
status, headers, _ = self.request("OPTIONS", "/")
|
||||
|
Loading…
Reference in New Issue
Block a user