-
-
Notifications
You must be signed in to change notification settings - Fork 723
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 0.30.4 issue with connection close header #2408
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
52ff0c1
fix server waiting state with connection close header
theyashl 3c8a441
added test case for closing post connection with connection header
theyashl 36a3853
removed post without body test case with connection close header
theyashl d034d09
removed unnecessary line removal
theyashl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,22 @@ | |
|
||
CONNECTION_CLOSE_REQUEST = b"\r\n".join([b"GET / HTTP/1.1", b"Host: example.org", b"Connection: close", b"", b""]) | ||
|
||
CONNECTION_CLOSE_POST_REQUEST_WITH_BODY = b"\r\n".join( | ||
[ | ||
b"POST / HTTP/1.1", | ||
b"Host: example.org", | ||
b"Connection: close", | ||
b"Content-Type: application/json", | ||
b"Content-Length: 18", | ||
b"", | ||
b"{'hello': 'world'}", | ||
] | ||
) | ||
|
||
CONNECTION_CLOSE_POST_REQUEST_WITHOUT_BODY = b"\r\n".join( | ||
[b"POST / HTTP/1.1", b"Host: example.org", b"Connection: close", b"", b""] | ||
) | ||
|
||
REQUEST_AFTER_CONNECTION_CLOSE = b"\r\n".join( | ||
[ | ||
b"GET / HTTP/1.1", | ||
|
@@ -998,8 +1014,8 @@ async def test_return_close_header(http_protocol_cls: HTTPProtocol): | |
|
||
|
||
async def test_close_connection_with_multiple_requests(http_protocol_cls: HTTPProtocol): | ||
app = Response("Hello, world", media_type="text/plain") | ||
|
||
response_content = b"Hello, world" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't add a diff here please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed diffs |
||
app = Response(response_content, media_type="text/plain") | ||
protocol = get_connected_protocol(app, http_protocol_cls) | ||
protocol.data_received(REQUEST_AFTER_CONNECTION_CLOSE) | ||
await protocol.loop.run_one() | ||
|
@@ -1009,6 +1025,29 @@ async def test_close_connection_with_multiple_requests(http_protocol_cls: HTTPPr | |
# NOTE: We need to use `.lower()` because H11 implementation doesn't allow Uvicorn | ||
# to lowercase them. See: https://github.com/python-hyper/h11/issues/156 | ||
assert b"connection: close" in protocol.transport.buffer.lower() | ||
assert response_content in protocol.transport.buffer | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"req_body", [CONNECTION_CLOSE_POST_REQUEST_WITH_BODY, CONNECTION_CLOSE_POST_REQUEST_WITHOUT_BODY] | ||
) | ||
async def test_close_connection_with_post_request(req_body: bytes, http_protocol_cls: HTTPProtocol): | ||
async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable): | ||
body = b"" | ||
more_body = True | ||
while more_body: | ||
message = await receive() | ||
assert message["type"] == "http.request" | ||
body += message.get("body", b"") | ||
more_body = message.get("more_body", False) | ||
response = Response(b"Body: " + body, media_type="text/plain") | ||
await response(scope, receive, send) | ||
|
||
protocol = get_connected_protocol(app, http_protocol_cls) | ||
protocol.data_received(req_body) | ||
await protocol.loop.run_one() | ||
assert b"HTTP/1.1 200 OK" in protocol.transport.buffer | ||
assert req_body.split(b"\r\n")[-1] in protocol.transport.buffer | ||
|
||
|
||
async def test_iterator_headers(http_protocol_cls: HTTPProtocol): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this one. The above case is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this case of POST without body. Kept POST with body and connection close header