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: Server's http.Request strips Transfer-Encoding header #11675

Closed
solderjs opened this issue Jul 11, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@solderjs
Copy link

commented Jul 11, 2015

Probably a low-priority issue. Not a big deal, just a little confusing.

Also, I'm well-aware that browsers don't send with Transfer-Encoding: chunked, but there are clients that can.

Perhaps this is intentional, but if so, I didn't see it in the documentation.

Here's a little demo code

func (m *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  fmt.Println(r.RequestURI)
  fmt.Println(r.URL)
  fmt.Println(r.Method)
  for k, v := range r.Header {
    fmt.Println(k, v)
  }
  fmt.Println(r.Body)

  fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
# curl can send it
http://localhost/pizza -X POST -H "Transfer-Encoding: chunked" -d 'foo=bar&baz=grault' -vv

# the server doesn't show it
/
/
POST
User-Agent [curl/7.37.1]
Accept [*/*]
Content-Type [application/x-www-form-urlencoded]
&{0xc20807c300 0xc208032340 0xc20805c240 false {0 0} false}
# yet other headers show up as expected
http://localhost/pizza -X POST -H "X-Transfer-Encoding: chunked" -d 'foo=bar&baz=grault' -vv

# server shows this
/
/
POST
X-Transfer-Encoding [chunked]
Content-Length [18]
Content-Type [application/x-www-form-urlencoded]
User-Agent [curl/7.37.1]
Accept [*/*]
&{0xc2080aa700 <nil> <nil> false {0 0} false}

@bradfitz bradfitz changed the title Server's http.Request strips Transfer-Encoding header net/http: Server's http.Request strips Transfer-Encoding header Jul 14, 2015

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jul 22, 2015

@bradfitz

Go does this intentionally: it handles decoding the transfer-encoding, so by the time the body arrives at ServeHTTP the handler should not care at all. I believe this is working as intended.

Do you need the Transfer-Encoding for some reason?

@rsc rsc closed this Aug 6, 2015

@golang golang locked and limited conversation to collaborators Aug 5, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.