@@ -913,14 +913,18 @@ func (sc *serverConn) serve(conf http2Config) {
913
913
sc .vlogf ("http2: server connection from %v on %p" , sc .conn .RemoteAddr (), sc .hs )
914
914
}
915
915
916
+ settings := writeSettings {
917
+ {SettingMaxFrameSize , conf .MaxReadFrameSize },
918
+ {SettingMaxConcurrentStreams , sc .advMaxStreams },
919
+ {SettingMaxHeaderListSize , sc .maxHeaderListSize ()},
920
+ {SettingHeaderTableSize , conf .MaxDecoderHeaderTableSize },
921
+ {SettingInitialWindowSize , uint32 (sc .initialStreamRecvWindowSize )},
922
+ }
923
+ if ! disableExtendedConnectProtocol {
924
+ settings = append (settings , Setting {SettingEnableConnectProtocol , 1 })
925
+ }
916
926
sc .writeFrame (FrameWriteRequest {
917
- write : writeSettings {
918
- {SettingMaxFrameSize , conf .MaxReadFrameSize },
919
- {SettingMaxConcurrentStreams , sc .advMaxStreams },
920
- {SettingMaxHeaderListSize , sc .maxHeaderListSize ()},
921
- {SettingHeaderTableSize , conf .MaxDecoderHeaderTableSize },
922
- {SettingInitialWindowSize , uint32 (sc .initialStreamRecvWindowSize )},
923
- },
927
+ write : settings ,
924
928
})
925
929
sc .unackedSettings ++
926
930
@@ -1782,6 +1786,9 @@ func (sc *serverConn) processSetting(s Setting) error {
1782
1786
sc .maxFrameSize = int32 (s .Val ) // the maximum valid s.Val is < 2^31
1783
1787
case SettingMaxHeaderListSize :
1784
1788
sc .peerMaxHeaderListSize = s .Val
1789
+ case SettingEnableConnectProtocol :
1790
+ // Receipt of this parameter by a server does not
1791
+ // have any impact
1785
1792
default :
1786
1793
// Unknown setting: "An endpoint that receives a SETTINGS
1787
1794
// frame with any unknown or unsupported identifier MUST
@@ -2212,11 +2219,17 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
2212
2219
scheme : f .PseudoValue ("scheme" ),
2213
2220
authority : f .PseudoValue ("authority" ),
2214
2221
path : f .PseudoValue ("path" ),
2222
+ protocol : f .PseudoValue ("protocol" ),
2223
+ }
2224
+
2225
+ // extended connect is disabled, so we should not see :protocol
2226
+ if disableExtendedConnectProtocol && rp .protocol != "" {
2227
+ return nil , nil , sc .countError ("bad_connect" , streamError (f .StreamID , ErrCodeProtocol ))
2215
2228
}
2216
2229
2217
2230
isConnect := rp .method == "CONNECT"
2218
2231
if isConnect {
2219
- if rp .path != "" || rp .scheme != "" || rp .authority == "" {
2232
+ if rp .protocol == "" && ( rp . path != "" || rp .scheme != "" || rp .authority == "" ) {
2220
2233
return nil , nil , sc .countError ("bad_connect" , streamError (f .StreamID , ErrCodeProtocol ))
2221
2234
}
2222
2235
} else if rp .method == "" || rp .path == "" || (rp .scheme != "https" && rp .scheme != "http" ) {
@@ -2240,6 +2253,9 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
2240
2253
if rp .authority == "" {
2241
2254
rp .authority = rp .header .Get ("Host" )
2242
2255
}
2256
+ if rp .protocol != "" {
2257
+ rp .header .Set (":protocol" , rp .protocol )
2258
+ }
2243
2259
2244
2260
rw , req , err := sc .newWriterAndRequestNoBody (st , rp )
2245
2261
if err != nil {
@@ -2266,6 +2282,7 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
2266
2282
type requestParam struct {
2267
2283
method string
2268
2284
scheme , authority , path string
2285
+ protocol string
2269
2286
header http.Header
2270
2287
}
2271
2288
@@ -2307,7 +2324,7 @@ func (sc *serverConn) newWriterAndRequestNoBody(st *stream, rp requestParam) (*r
2307
2324
2308
2325
var url_ * url.URL
2309
2326
var requestURI string
2310
- if rp .method == "CONNECT" {
2327
+ if rp .method == "CONNECT" && rp . protocol == "" {
2311
2328
url_ = & url.URL {Host : rp .authority }
2312
2329
requestURI = rp .authority // mimic HTTP/1 server behavior
2313
2330
} else {
0 commit comments