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: 204 and 100 response handling problems #6685

Closed
bradfitz opened this issue Oct 29, 2013 · 5 comments
Closed

net/http: 204 and 100 response handling problems #6685

bradfitz opened this issue Oct 29, 2013 · 5 comments
Milestone

Comments

@bradfitz
Copy link
Contributor

(Mirroring bug here from report elsewhere)

Problem (what you see vs. what you expected your program to do):
Inconsistent (and by some measure incorrect handling) of 204 responses in Go http server.

Steps to reproduce:
Run  the following trivial server:
package main

import (
       "net/http"
)

type Hello struct{}

func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) {
       w.Header().Set("Content-Length", "4")
       w.Header().Set("Content-Type", "test/plain")
       w.WriteHeader(204)
       w.Write([]byte("data"))
}

func main() {
       var h Hello
       http.ListenAndServe("localhost:4000", h)
}

Telnet session output:
> telnet localhost 4000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 204 No Content
Content-Length: 4
Content-Type: test/plain
Date: Tue, 29 Oct 2013 20:13:15 GMT

data

-- 204 must have no body, as per HTTP specification and here it is passed on to the
client.

Now, if we change the above code to return 304, instead of 204 we get:
>telnet localhost 4000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 304 Not Modified
Date: Tue, 29 Oct 2013 20:12:43 GMT



As you can see in case of 304 Go HTTP server not only trimmed body but also removed
headers.
It should do the same with 204 responses.

Same happens with 100 responses, which must not that any body as well, but the body is
being returned.
@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 1:

Labels changed: added release-go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 2:

Labels changed: removed go1.3.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added repo-main.

@bradfitz
Copy link
Contributor Author

Comment 4:

Sent https://golang.org/cl/53290044

Status changed to Started.

@bradfitz
Copy link
Contributor Author

Comment 5:

This issue was closed by revision 3647729.

Status changed to Fixed.

@bradfitz bradfitz self-assigned this Jan 16, 2014
@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@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