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

net/http: Response.Write should write Content-Length: 0 header if present and not chunked #6762

Closed
gopherbot opened this issue Nov 14, 2013 · 7 comments

Comments

@gopherbot
Copy link

by islandberry23:

I am filing this issue as requested at
https://groups.google.com/forum/#!topic/golang-nuts/8D_tno7WxaY

The transferWriter decides if it should write the content-length header at:
https://code.google.com/p/go/source/browse/src/pkg/net/http/transfer.go?name=release&;r=63dcf9ca33a74dec605f6156393d719150ad6e2e#116

This function returns false for a Content-Length: 0 response unless the transfer
encoding is explicitly set to identity.  

If a response has a content length header and the transfer encoding is not explicitly
set to chunked, then the content length header should be written to the output. This is
true even of the content length is zero. Zero is a valid response body size.
@bradfitz
Copy link
Contributor

Comment 1:

Please provide an example program in this bug that behaves incorrectly.

Owner changed to @bradfitz.

Status changed to Accepted.

@gopherbot
Copy link
Author

Comment 2 by islandberry23:

http://play.golang.org/p/VMPK1Sc2tk
The content length should be written in all cases.

@bradfitz
Copy link
Contributor

Comment 3:

I don't think we can change this.  A Content-Length of zero is the zero value of that
field of a Response.  This would affect other users.
What is your actual problem?  Maybe there's an alternate fix in the http server.  I
suspect you're proposing the solution instead of describing the problem.

@gopherbot
Copy link
Author

Comment 4 by islandberry23:

You can change this by adding a boolean field to note if the content length header was
set or not.
I filed this issue at the request of the people participating in the linked thread.
Please contact them to discuss the actual problem.

@bradfitz
Copy link
Contributor

Comment 5:

[+hi wang, the original poster on this topic]

Status changed to WaitingForReply.

@ceh
Copy link
Contributor

ceh commented Nov 14, 2013

Comment 6:

Duplicate of issue #5381?

@bradfitz
Copy link
Contributor

Comment 7:

Thanks.

Status changed to Duplicate.

Merged into issue #5381.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants