File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,15 @@ func NewHandler(h http.Handler, s *http2.Server) http.Handler {
70
70
}
71
71
}
72
72
73
+ // extractServer extracts existing http.Server instance from http.Request or create an empty http.Server
74
+ func extractServer (r * http.Request ) * http.Server {
75
+ server , ok := r .Context ().Value (http .ServerContextKey ).(* http.Server )
76
+ if ok {
77
+ return server
78
+ }
79
+ return new (http.Server )
80
+ }
81
+
73
82
// ServeHTTP implement the h2c support that is enabled by h2c.GetH2CHandler.
74
83
func (s h2cHandler ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
75
84
// Handle h2c with prior knowledge (RFC 7540 Section 3.4)
@@ -87,6 +96,7 @@ func (s h2cHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
87
96
defer conn .Close ()
88
97
s .s .ServeConn (conn , & http2.ServeConnOpts {
89
98
Context : r .Context (),
99
+ BaseConfig : extractServer (r ),
90
100
Handler : s .Handler ,
91
101
SawClientPreface : true ,
92
102
})
@@ -104,6 +114,7 @@ func (s h2cHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
104
114
defer conn .Close ()
105
115
s .s .ServeConn (conn , & http2.ServeConnOpts {
106
116
Context : r .Context (),
117
+ BaseConfig : extractServer (r ),
107
118
Handler : s .Handler ,
108
119
UpgradeRequest : r ,
109
120
Settings : settings ,
You can’t perform that action at this time.
0 commit comments