fix: header parsing in a 100 continue response. #3010
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Restore
response_class
attribute unconditionally, regardless of whether headerExpect: 100-continue
appears.The event flow to reproduce the bug:
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 theMissingHeaderBodySeparatorDefect
occurs.