Skip to content
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

fix: header parsing in a 100 continue response. #3010

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

missingjs
Copy link

@missingjs missingjs commented Aug 29, 2023

Restore response_class attribute unconditionally, regardless of whether header Expect: 100-continue appears.

The event flow to reproduce the bug:

  1. The client sends a request with Expect: 100-continue header.
  2. The server sends a normal response other than 100 Continue.
  3. The client consumes the response, both header and body.

Until now, everything is fine. Let's continue:
4. The client sends another request with Expect: 100-continue header.
5. The server sends a 100 continue response.
6. The client then continue to send body to server.
7. The server sends a normal response other than 100 Continue.

After all the operations above, the client begin to consume the response. But it will skip the status line, and feed the status line and headers together to the header parser - email.parser.Parser.parsestr(). The parser will fail with an error called 'MissingHeaderBodySeparatorDefect'.

Since the headers including 'Content-Length' not be parsed, the content length of the response will be None. So the client will try to read 65536 bytes from the socket connection. Actually there may be no more data sent from the server, so the read() on socket will be blocked, until timeout or the server close the connection.

Why the client skip the status line? Because when the request header contans Expect: 100-continue but server sends a non-100 response, the class 'AWSConnection' will replace the attribute 'response_class' with a wrapped class. The wrapped class has a fixed status line, it will not consume the real status line, so the real status line will be fed to header parser together with the header fields. Then the MissingHeaderBodySeparatorDefect occurs.

Qiming Tang added 2 commits August 29, 2023 15:16
Restore `response_class` attribute unconditionally,
regardless of whether header `Expect: 100-continue` appears.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant