-
-
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
Ensure empty body response for 1xx/204/304 per RFC 9112 sec 6.3 (#7756) #7778
Ensure empty body response for 1xx/204/304 per RFC 9112 sec 6.3 (#7756) #7778
Conversation
…libs#7756) <!-- Thank you for your contribution! --> `Transfer-Encoding` and `Content-Length` will be removed from the server response when sending a 1xx (Informational), 204 (No Content), or 304 (Not Modified) status since no body is expected for these status codes - `Content-Length` forbidden on 1xx/204 per https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2 and discouraged on 304 per https://datatracker.ietf.org/doc/html/rfc7232#section-4.1 We need to ensure `Content-Length` is kept for `HEAD` to ensure keep-alive works as expected and is allowed per https://datatracker.ietf.org/doc/html/rfc2616#section-14.13 - `Transfer-Encoding` removed per https://datatracker.ietf.org/doc/html/rfc9112#section-6.1 > any recipient on the response chain (including the origin server) can remove transfer codings when they are not needed. `aiohttp` would incorrectly send an body of `0\r\n\r\n` when `chunked` was set for `Transfer-Encoding` with the above status code. This change ensures `aiohttp` does not send these invalid bodies. The `Transfer-Encoding` and `Content-Length` headers will be removed when sending a 1xx (Informational), 204 (No Content), or 304 (Not Modified) except for `HEAD` responses since these status since no body is expected for these status codes. An invalid body of `0\r\n\r\n` will no longer be sent with these status codes. <!-- Are there any issues opened that will be resolved by merging this change? --> - [x] I think the code is well written - [x] Unit tests for the changes exist - [ ] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` * The format is <Name> <Surname>. * Please keep alphabetical order, the file is sorted by names. - [x] Add a new news fragment into the `CHANGES` folder * name it `<issue_id>.<type>` for example (588.bugfix) * if you don't have an `issue_id` change it to the pr id after creating the pr * ensure type is one of the following: * `.feature`: Signifying a new feature. * `.bugfix`: Signifying a bug fix. * `.doc`: Signifying a documentation improvement. * `.removal`: Signifying a deprecation or removal of public API. * `.misc`: A ticket has been closed, but it is not of interest to users. * Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files." TODO: - [x] figure out why client closes connection on HEAD requests with content length - [x] figure out why client functional tests fail with AIOHTTP_NO_EXTENSIONS=1 `test_keepalive_after_empty_body_status` and `test_keepalive_after_empty_body_status_stream_response` -- They do not fail anymore after the fixed in aio-libs#7755 - [x] timeline - [x] more functional testing --------- Co-authored-by: Sam Bull <git@sambull.org> (cherry picked from commit f63cf18)
Pushed this PR to production and all is well |
That's the second time pypy has segfaulted while building the dependencies today... |
Codecov Report
@@ Coverage Diff @@
## 3.9 #7778 +/- ##
==========================================
+ Coverage 97.31% 97.32% +0.01%
==========================================
Files 107 107
Lines 32005 32203 +198
Branches 3735 3748 +13
==========================================
+ Hits 31145 31343 +198
Misses 654 654
Partials 206 206
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
…libs#7756) (aio-libs#7778) <!-- Thank you for your contribution! --> `Transfer-Encoding` and `Content-Length` will be removed from the server response when sending a 1xx (Informational), 204 (No Content), or 304 (Not Modified) status since no body is expected for these status codes - `Content-Length` forbidden on 1xx/204 per https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2 and discouraged on 304 per https://datatracker.ietf.org/doc/html/rfc7232#section-4.1 We need to ensure `Content-Length` is kept for `HEAD` to ensure keep-alive works as expected and is allowed per https://datatracker.ietf.org/doc/html/rfc2616#section-14.13 - `Transfer-Encoding` removed per https://datatracker.ietf.org/doc/html/rfc9112#section-6.1 > any recipient on the response chain (including the origin server) can remove transfer codings when they are not needed. `aiohttp` would incorrectly send an body of `0\r\n\r\n` when `chunked` was set for `Transfer-Encoding` with the above status code. This change ensures `aiohttp` does not send these invalid bodies. The `Transfer-Encoding` and `Content-Length` headers will be removed when sending a 1xx (Informational), 204 (No Content), or 304 (Not Modified) except for `HEAD` responses since these status since no body is expected for these status codes. An invalid body of `0\r\n\r\n` will no longer be sent with these status codes. <!-- Are there any issues opened that will be resolved by merging this change? --> - [x] I think the code is well written - [x] Unit tests for the changes exist - [ ] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` * The format is <Name> <Surname>. * Please keep alphabetical order, the file is sorted by names. - [x] Add a new news fragment into the `CHANGES` folder * name it `<issue_id>.<type>` for example (588.bugfix) * if you don't have an `issue_id` change it to the pr id after creating the pr * ensure type is one of the following: * `.feature`: Signifying a new feature. * `.bugfix`: Signifying a bug fix. * `.doc`: Signifying a documentation improvement. * `.removal`: Signifying a deprecation or removal of public API. * `.misc`: A ticket has been closed, but it is not of interest to users. * Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files." TODO: - [x] figure out why client closes connection on HEAD requests with content length - [x] figure out why client functional tests fail with AIOHTTP_NO_EXTENSIONS=1 `test_keepalive_after_empty_body_status` and `test_keepalive_after_empty_body_status_stream_response` -- They do not fail anymore after the fixed in aio-libs#7755 - [x] timeline - [x] more functional testing --------- Co-authored-by: Sam Bull <git@sambull.org> (cherry picked from commit f63cf18) <!-- Thank you for your contribution! --> <!-- Please give a short brief about these changes. --> <!-- Outline any notable behaviour for the end users. --> <!-- Are there any issues opened that will be resolved by merging this change? --> - [ ] I think the code is well written - [ ] Unit tests for the changes exist - [ ] Documentation reflects the changes - [ ] If you provide code modification, please add yourself to `CONTRIBUTORS.txt` * The format is <Name> <Surname>. * Please keep alphabetical order, the file is sorted by names. - [ ] Add a new news fragment into the `CHANGES` folder * name it `<issue_id>.<type>` for example (588.bugfix) * if you don't have an `issue_id` change it to the pr id after creating the pr * ensure type is one of the following: * `.feature`: Signifying a new feature. * `.bugfix`: Signifying a bug fix. * `.doc`: Signifying a documentation improvement. * `.removal`: Signifying a deprecation or removal of public API. * `.misc`: A ticket has been closed, but it is not of interest to users. * Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."
Transfer-Encoding
andContent-Length
will be removed from the server response when sending a 1xx (Informational), 204 (No Content), or 304 (Not Modified) status since no body is expected for these status codesContent-Length
forbidden on 1xx/204 per https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2 and discouraged on 304 perhttps://datatracker.ietf.org/doc/html/rfc7232#section-4.1
We need to ensure
Content-Length
is kept forHEAD
to ensure keep-alive works as expected and is allowed perhttps://datatracker.ietf.org/doc/html/rfc2616#section-14.13
Transfer-Encoding
removed per https://datatracker.ietf.org/doc/html/rfc9112#section-6.1aiohttp
would incorrectly send an body of0\r\n\r\n
whenchunked
was set forTransfer-Encoding
with the above status code.This change ensures
aiohttp
does not send these invalid bodies.The
Transfer-Encoding
andContent-Length
headers will be removed when sending a 1xx (Informational), 204 (No Content), or 304 (Not Modified) except forHEAD
responses since these status since no body is expected for these status codes.An invalid body of
0\r\n\r\n
will no longer be sent with these status codes.CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature. *.bugfix
: Signifying a bug fix. *.doc
: Signifying a documentation improvement. *.removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.TODO:
test_keepalive_after_empty_body_status
andtest_keepalive_after_empty_body_status_stream_response
-- They do not fail anymore after the fixed inFix py http parser not treating 204/304/1xx as an empty body #7755
Co-authored-by: Sam Bull git@sambull.org
(cherry picked from commit f63cf18)
What do these changes do?
Are there changes in behavior for the user?
Related issue number
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.