@@ -935,14 +935,18 @@ func (sc *serverConn) serve() {
935
935
sc .vlogf ("http2: server connection from %v on %p" , sc .conn .RemoteAddr (), sc .hs )
936
936
}
937
937
938
+ settings := writeSettings {
939
+ {SettingMaxFrameSize , sc .srv .maxReadFrameSize ()},
940
+ {SettingMaxConcurrentStreams , sc .advMaxStreams },
941
+ {SettingMaxHeaderListSize , sc .maxHeaderListSize ()},
942
+ {SettingHeaderTableSize , sc .srv .maxDecoderHeaderTableSize ()},
943
+ {SettingInitialWindowSize , uint32 (sc .srv .initialStreamRecvWindowSize ())},
944
+ }
945
+ if ! disableExtendedConnectProtocol {
946
+ settings = append (settings , Setting {SettingEnableConnectProtocol , 1 })
947
+ }
938
948
sc .writeFrame (FrameWriteRequest {
939
- write : writeSettings {
940
- {SettingMaxFrameSize , sc .srv .maxReadFrameSize ()},
941
- {SettingMaxConcurrentStreams , sc .advMaxStreams },
942
- {SettingMaxHeaderListSize , sc .maxHeaderListSize ()},
943
- {SettingHeaderTableSize , sc .srv .maxDecoderHeaderTableSize ()},
944
- {SettingInitialWindowSize , uint32 (sc .srv .initialStreamRecvWindowSize ())},
945
- },
949
+ write : settings ,
946
950
})
947
951
sc .unackedSettings ++
948
952
@@ -1757,6 +1761,9 @@ func (sc *serverConn) processSetting(s Setting) error {
1757
1761
sc .maxFrameSize = int32 (s .Val ) // the maximum valid s.Val is < 2^31
1758
1762
case SettingMaxHeaderListSize :
1759
1763
sc .peerMaxHeaderListSize = s .Val
1764
+ case SettingEnableConnectProtocol :
1765
+ // Receipt of this parameter by a server does not
1766
+ // have any impact
1760
1767
default :
1761
1768
// Unknown setting: "An endpoint that receives a SETTINGS
1762
1769
// frame with any unknown or unsupported identifier MUST
@@ -2187,11 +2194,17 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
2187
2194
scheme : f .PseudoValue ("scheme" ),
2188
2195
authority : f .PseudoValue ("authority" ),
2189
2196
path : f .PseudoValue ("path" ),
2197
+ protocol : f .PseudoValue ("protocol" ),
2198
+ }
2199
+
2200
+ // extended connect is disabled, so we should not see :protocol
2201
+ if disableExtendedConnectProtocol && rp .protocol != "" {
2202
+ return nil , nil , sc .countError ("bad_connect" , streamError (f .StreamID , ErrCodeProtocol ))
2190
2203
}
2191
2204
2192
2205
isConnect := rp .method == "CONNECT"
2193
2206
if isConnect {
2194
- if rp .path != "" || rp .scheme != "" || rp .authority == "" {
2207
+ if rp .protocol == "" && ( rp . path != "" || rp .scheme != "" || rp .authority == "" ) {
2195
2208
return nil , nil , sc .countError ("bad_connect" , streamError (f .StreamID , ErrCodeProtocol ))
2196
2209
}
2197
2210
} else if rp .method == "" || rp .path == "" || (rp .scheme != "https" && rp .scheme != "http" ) {
@@ -2215,6 +2228,9 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
2215
2228
if rp .authority == "" {
2216
2229
rp .authority = rp .header .Get ("Host" )
2217
2230
}
2231
+ if rp .protocol != "" {
2232
+ rp .header .Set (":protocol" , rp .protocol )
2233
+ }
2218
2234
2219
2235
rw , req , err := sc .newWriterAndRequestNoBody (st , rp )
2220
2236
if err != nil {
@@ -2241,6 +2257,7 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
2241
2257
type requestParam struct {
2242
2258
method string
2243
2259
scheme , authority , path string
2260
+ protocol string
2244
2261
header http.Header
2245
2262
}
2246
2263
@@ -2282,7 +2299,7 @@ func (sc *serverConn) newWriterAndRequestNoBody(st *stream, rp requestParam) (*r
2282
2299
2283
2300
var url_ * url.URL
2284
2301
var requestURI string
2285
- if rp .method == "CONNECT" {
2302
+ if rp .method == "CONNECT" && rp . protocol == "" {
2286
2303
url_ = & url.URL {Host : rp .authority }
2287
2304
requestURI = rp .authority // mimic HTTP/1 server behavior
2288
2305
} else {
0 commit comments