summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/http2/h2c
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/net/http2/h2c')
-rw-r--r--vendor/golang.org/x/net/http2/h2c/h2c.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/vendor/golang.org/x/net/http2/h2c/h2c.go b/vendor/golang.org/x/net/http2/h2c/h2c.go
index c3df711d..2b77ffda 100644
--- a/vendor/golang.org/x/net/http2/h2c/h2c.go
+++ b/vendor/golang.org/x/net/http2/h2c/h2c.go
@@ -70,6 +70,15 @@ func NewHandler(h http.Handler, s *http2.Server) http.Handler {
}
}
+// extractServer extracts existing http.Server instance from http.Request or create an empty http.Server
+func extractServer(r *http.Request) *http.Server {
+ server, ok := r.Context().Value(http.ServerContextKey).(*http.Server)
+ if ok {
+ return server
+ }
+ return new(http.Server)
+}
+
// ServeHTTP implement the h2c support that is enabled by h2c.GetH2CHandler.
func (s h2cHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Handle h2c with prior knowledge (RFC 7540 Section 3.4)
@@ -87,6 +96,7 @@ func (s h2cHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer conn.Close()
s.s.ServeConn(conn, &http2.ServeConnOpts{
Context: r.Context(),
+ BaseConfig: extractServer(r),
Handler: s.Handler,
SawClientPreface: true,
})
@@ -104,6 +114,7 @@ func (s h2cHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer conn.Close()
s.s.ServeConn(conn, &http2.ServeConnOpts{
Context: r.Context(),
+ BaseConfig: extractServer(r),
Handler: s.Handler,
UpgradeRequest: r,
Settings: settings,