You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(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.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: