-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with HEAD responses #820
Comments
Agree with all your proposals. |
Probably just one PR. Proposed fix for the server (web_reqrep.py): def should_send_body(self):
return (self._req.method.lower() != 'head' and
self._status not in [204,304])
@asyncio.coroutine
def write_eof(self):
try:
body = self._body
if body is not None and self.should_send_body():
self.write(body)
finally:
self.set_tcp_nodelay(True)
yield from super().write_eof() I don't know if it is possible to do something on the client side, because server can set Content-length header to "what it would have been if the request method had been GET" so there's no way to tell how much data (if any) should be read. |
User still may write
Honestly I not sure if we need to do anything on server side. |
I agree, if they're trying to shoot yourself into leg, there's no way we can prevent it. Real life use case examples are: using HEAD to check existence of resource, cache probing/flushing or bandwidth saving measures for mobile devices. I think we need to do something because at least 404 response is created by server itself outside user's control. |
Fixed by #838 |
RFC7231 forbids sending body content when responding to HEAD requests. Believing that servers are RFC compliant, aiohttp client is not parsing body of HEAD responses. Content of body stays in buffer and when parsing next response from the same session/connection BadStatusLine is raised. Not all servers are compliant, and unfortunately aiohttp server is one of them. Example code is bellow.
I believe the correct behaviour should be according to Postel's law: server won't send body in response to HEAD and will read and discard (maybe with warning) non-compliant responses.
The text was updated successfully, but these errors were encountered: