mirror of
https://github.com/golang/go
synced 2024-11-18 00:34:44 -07:00
net/http/httputil: pass through any "TE: trailers" header to backend
Fixes #21096 Change-Id: I2a4688a79bdaa25b4e8ef38e3390d93d3d0bce04 Reviewed-on: https://go-review.googlesource.com/115135 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
6c6e22e5a9
commit
9e56156ade
@ -178,9 +178,20 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
// important is "Connection" because we want a persistent
|
// important is "Connection" because we want a persistent
|
||||||
// connection, regardless of what the client sent to us.
|
// connection, regardless of what the client sent to us.
|
||||||
for _, h := range hopHeaders {
|
for _, h := range hopHeaders {
|
||||||
if outreq.Header.Get(h) != "" {
|
hv := outreq.Header.Get(h)
|
||||||
outreq.Header.Del(h)
|
if hv == "" {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
if h == "Te" && hv == "trailers" {
|
||||||
|
// Issue 21096: tell backend applications that
|
||||||
|
// care about trailer support that we support
|
||||||
|
// trailers. (We do, but we don't go out of
|
||||||
|
// our way to advertise that unless the
|
||||||
|
// incoming client request thought it was
|
||||||
|
// worth mentioning)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
outreq.Header.Del(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
|
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
|
||||||
|
@ -49,6 +49,9 @@ func TestReverseProxy(t *testing.T) {
|
|||||||
if c := r.Header.Get("Connection"); c != "" {
|
if c := r.Header.Get("Connection"); c != "" {
|
||||||
t.Errorf("handler got Connection header value %q", c)
|
t.Errorf("handler got Connection header value %q", c)
|
||||||
}
|
}
|
||||||
|
if c := r.Header.Get("Te"); c != "trailers" {
|
||||||
|
t.Errorf("handler got Te header value %q; want 'trailers'", c)
|
||||||
|
}
|
||||||
if c := r.Header.Get("Upgrade"); c != "" {
|
if c := r.Header.Get("Upgrade"); c != "" {
|
||||||
t.Errorf("handler got Upgrade header value %q", c)
|
t.Errorf("handler got Upgrade header value %q", c)
|
||||||
}
|
}
|
||||||
@ -85,6 +88,7 @@ func TestReverseProxy(t *testing.T) {
|
|||||||
getReq, _ := http.NewRequest("GET", frontend.URL, nil)
|
getReq, _ := http.NewRequest("GET", frontend.URL, nil)
|
||||||
getReq.Host = "some-name"
|
getReq.Host = "some-name"
|
||||||
getReq.Header.Set("Connection", "close")
|
getReq.Header.Set("Connection", "close")
|
||||||
|
getReq.Header.Set("Te", "trailers")
|
||||||
getReq.Header.Set("Proxy-Connection", "should be deleted")
|
getReq.Header.Set("Proxy-Connection", "should be deleted")
|
||||||
getReq.Header.Set("Upgrade", "foo")
|
getReq.Header.Set("Upgrade", "foo")
|
||||||
getReq.Close = true
|
getReq.Close = true
|
||||||
|
Loading…
Reference in New Issue
Block a user