Browse Source

http2: fix bug in earlier CL 123615

I both forgot that this list could contain duplicates, and I had
forgot to run the net/http tests against CL 123615 before mailing it,
which ended up catching this bug.

The diff of this file from the commit before CL 123615 (a45b4abe^ ==
cffdcf672) to this commit is:

    https://gist.github.com/bradfitz/0b7abf8fa421515aed9c4d55ce3a1994

... effectively reverting much of CL 123615 and just moving the 1xx
handling down lower.

Updates golang/go#26189 (fixes after vendor into std)
Updates golang/go#17739

Change-Id: Ib63060b0bb9721883b4b91a983b6e117994faeb9
Reviewed-on: https://go-review.googlesource.com/123675
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Brad Fitzpatrick 7 years ago
parent
commit
d0887baf81
1 changed files with 15 additions and 20 deletions
  1. 15 20
      http2/transport.go

+ 15 - 20
http2/transport.go

@@ -1763,11 +1763,24 @@ func (rl *clientConnReadLoop) handleResponse(cs *clientStream, f *MetaHeadersFra
 	}
 	}
 
 
 	header := make(http.Header)
 	header := make(http.Header)
-	var trailerValue string
+	res := &http.Response{
+		Proto:      "HTTP/2.0",
+		ProtoMajor: 2,
+		Header:     header,
+		StatusCode: statusCode,
+		Status:     status + " " + http.StatusText(statusCode),
+	}
 	for _, hf := range f.RegularFields() {
 	for _, hf := range f.RegularFields() {
 		key := http.CanonicalHeaderKey(hf.Name)
 		key := http.CanonicalHeaderKey(hf.Name)
 		if key == "Trailer" {
 		if key == "Trailer" {
-			trailerValue = hf.Value
+			t := res.Trailer
+			if t == nil {
+				t = make(http.Header)
+				res.Trailer = t
+			}
+			foreachHeaderElement(hf.Value, func(v string) {
+				t[http.CanonicalHeaderKey(v)] = nil
+			})
 		} else {
 		} else {
 			header[key] = append(header[key], hf.Value)
 			header[key] = append(header[key], hf.Value)
 		}
 		}
@@ -1794,24 +1807,6 @@ func (rl *clientConnReadLoop) handleResponse(cs *clientStream, f *MetaHeadersFra
 		return nil, nil
 		return nil, nil
 	}
 	}
 
 
-	res := &http.Response{
-		Proto:      "HTTP/2.0",
-		ProtoMajor: 2,
-		Header:     header,
-		StatusCode: statusCode,
-		Status:     status + " " + http.StatusText(statusCode),
-	}
-	if trailerValue != "" {
-		t := res.Trailer
-		if t == nil {
-			t = make(http.Header)
-			res.Trailer = t
-		}
-		foreachHeaderElement(trailerValue, func(v string) {
-			t[http.CanonicalHeaderKey(v)] = nil
-		})
-	}
-
 	streamEnded := f.StreamEnded()
 	streamEnded := f.StreamEnded()
 	isHead := cs.req.Method == "HEAD"
 	isHead := cs.req.Method == "HEAD"
 	if !streamEnded || isHead {
 	if !streamEnded || isHead {