Skip to content

Add Content-Length header for empty bytestream - #866

Merged
florimondmanca merged 1 commit into
encode:masterfrom
b0g3r:empty_bytestream_with_content_length
Mar 28, 2020
Merged

Add Content-Length header for empty bytestream#866
florimondmanca merged 1 commit into
encode:masterfrom
b0g3r:empty_bytestream_with_content_length

Conversation

@b0g3r

Copy link
Copy Markdown
Contributor

Reference: #861 (comment)

@b0g3r
b0g3r marked this pull request as ready for review March 17, 2020 06:54
@b0g3r
b0g3rforce-pushed the empty_bytestream_with_content_length branch from 1af18f9 to 2f146a3CompareMarch 17, 2020 06:54

@florimondmancaflorimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@florimondmancaflorimondmanca changed the title Add content-length header for empty bytestreamAdd Content-Length header for empty bytestreamMar 28, 2020
@florimondmanca
florimondmanca merged commit 939f3ce into encode:masterMar 28, 2020
@lovelydinosaur

Copy link
Copy Markdown
Contributor

I think we need to be more careful with this. Eg. we shouldn't be sending Content-Length: 0 on GET requests.

I note the RFC text wrt "A user agent SHOULD send a Content-Length in a request message when no Transfer-Encoding is sent and the request method defines a meaning for an enclosed payload body." although even in that case I'd like us to start by validating what the equivelent behaviour in urllib3/requests would be there.

@lovelydinosaur

Copy link
Copy Markdown
Contributor

I'd suggest we might want to start off with a PR reverting this change, since it improves the RFC behaviour in one case, but regresses it in another "A user agent SHOULD NOT send a Content-Length header field when the request message does not contain a payload body and the method semantics do not anticipate such a body."

We can then take a second look at this.

def test_no_content():
request = httpx.Request("GET", "http://example.org")
assert "Content-Length" not in request.headers
assert request.headers["Content-Length"] == "0"

@b0g3rb0g3rMar 30, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovelydinosaur added a commit that referenced this pull request Apr 8, 2020
lovelydinosaur added a commit that referenced this pull request Apr 8, 2020
Kludex referenced this pull request in pydantic/httpx2 May 11, 2026
Bumps [trio-typing](https://github.com/python-trio/trio-typing) from 0.9.0 to 0.10.0.
- [Commits](python-trio/trio-typing@v0.9.0...v0.10.0)
---
updated-dependencies:
- dependency-name: trio-typing
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@b0g3r@lovelydinosaur@florimondmanca