aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/readrequest_test.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-03-30 22:11:41 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2016-03-31 06:12:36 +0000
commita6557a05a03490af3b26f97f9a4ce99c7c773fe5 (patch)
tree5a31b5b08d2bb9b424f6b3c31416ec1773fb30b5 /src/net/http/readrequest_test.go
parent0026cb788b54e3108534992d98b7fec0cf96de17 (diff)
downloadgo-a6557a05a03490af3b26f97f9a4ce99c7c773fe5.tar.xz
net/http: allow Handlers to handle http2 upgrade PRI requests
The http2 spec defines a magic string which initates an http2 session: "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" It was intentionally chosen to kinda look like an HTTP request, but just different enough to break things not ready for it. This change makes Go ready for it. Notably: Go now accepts the request header (the prefix "PRI * HTTP/2.0\r\n\r\n") as a valid request, even though it doesn't have a Host header. But we now mark it as "Connection: close" and teach the Server to never read a second request from the connection once that's seen. If the http.Handler wants to deal with the upgrade, it has to hijack the request, read out the "body", compare it against "SM\r\n\r\n", and then speak http2. One of the new tests demonstrates that hijacking. Fixes #14451 Updates #14141 (h2c) Change-Id: Ib46142f31c55be7d00c56fa2624ec8a232e00c43 Reviewed-on: https://go-review.googlesource.com/21327 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/readrequest_test.go')
-rw-r--r--src/net/http/readrequest_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/net/http/readrequest_test.go b/src/net/http/readrequest_test.go
index 1225d97edb..4bf646b0a6 100644
--- a/src/net/http/readrequest_test.go
+++ b/src/net/http/readrequest_test.go
@@ -380,6 +380,27 @@ var reqTests = []reqTest{
noTrailer,
noError,
},
+
+ // http2 client preface:
+ {
+ "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n",
+ &Request{
+ Method: "PRI",
+ URL: &url.URL{
+ Path: "*",
+ },
+ Header: Header{},
+ Proto: "HTTP/2.0",
+ ProtoMajor: 2,
+ ProtoMinor: 0,
+ RequestURI: "*",
+ ContentLength: -1,
+ Close: true,
+ },
+ noBody,
+ noTrailer,
+ noError,
+ },
}
func TestReadRequest(t *testing.T) {