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/httputil: ReverseProxy does not pass unannounced trailers when there is no Body #29031

Closed
juliens opened this Issue Nov 30, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@juliens
Copy link
Contributor

juliens commented Nov 30, 2018

What version of Go are you using (go version)?

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/juliens/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/juliens/dev/go"
GOPROXY=""
GORACE=""
GOROOT="/home/juliens/go-current"
GOTMPDIR=""
GOTOOLDIR="/home/juliens/go-current/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build305055564=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I use the http.ReverseProxy.

What did you expect to see?

I want to see all unannonced trailers in the client.

What did you see instead?

No unannonced trailers.

More

func TestUnannoncedTrailer(t *testing.T) {
	backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.(http.Flusher).Flush()
		w.Header().Set(http.TrailerPrefix+"X-Unannounced-Trailer", "unannounced_trailer_value")
	}))
	defer backend.Close()
	backendURL, err := url.Parse(backend.URL)
	if err != nil {
		t.Fatal(err)
	}
	proxyHandler := NewSingleHostReverseProxy(backendURL)
	proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
	frontend := httptest.NewServer(proxyHandler)
	defer frontend.Close()
	frontendClient := frontend.Client()

	res, err := frontendClient.Get(frontend.URL)
	if err != nil {
		t.Fatalf("Get: %v", err)
	}

	ioutil.ReadAll(res.Body)

	if g, e := res.Trailer.Get("X-Unannounced-Trailer"), "unannounced_trailer_value"; g != e {
		t.Errorf("Trailer(X-Unannounced-Trailer) = %q ; want %q", g, e)
	}

}
@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Nov 30, 2018

Change https://golang.org/cl/151898 mentions this issue: net/http/httputil: fix announced trailers when body is empty

@bradfitz bradfitz added the NeedsFix label Nov 30, 2018

@bradfitz bradfitz added this to the Go1.12 milestone Nov 30, 2018

@gopherbot gopherbot closed this in 48399ca Dec 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment