Skip to content

x/net/http2: exclude some header from 1xx responses #134

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,14 @@ func (rws *responseWriterState) writeHeader(code int) {
// Per RFC 8297 we must not clear the current header map
h := rws.handlerHeader

_, cl := h["Content-Length"]
_, te := h["Transfer-Encoding"]
if cl || te {
h = h.Clone()
h.Del("Content-Length")
h.Del("Transfer-Encoding")
}

if rws.conn.writeHeaders(rws.stream, &writeResHeaders{
streamID: rws.stream.id,
httpResCode: code,
Expand Down
3 changes: 2 additions & 1 deletion http2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4392,6 +4392,7 @@ func TestServerSendsProcessing(t *testing.T) {
func TestServerSendsEarlyHints(t *testing.T) {
testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error {
h := w.Header()
h.Add("Content-Length", "123")
h.Add("Link", "</style.css>; rel=preload; as=style")
h.Add("Link", "</script.js>; rel=preload; as=script")
w.WriteHeader(http.StatusEarlyHints)
Expand Down Expand Up @@ -4437,7 +4438,7 @@ func TestServerSendsEarlyHints(t *testing.T) {
{"link", "</script.js>; rel=preload; as=script"},
{"link", "</foo.js>; rel=preload; as=script"},
{"content-type", "text/plain; charset=utf-8"},
{"content-length", "5"},
{"content-length", "123"},
}

if !reflect.DeepEqual(goth, wanth) {
Expand Down