add support for serializing Extended CONNECT requests (#3360)

This commit is contained in:
Marten Seemann
2022-04-02 19:55:42 +01:00
committed by GitHub
parent 26fbf99275
commit d1498c360e
2 changed files with 46 additions and 11 deletions

View File

@@ -113,7 +113,9 @@ func (w *requestWriter) writeHeaders(wr io.Writer, req *http.Request, gzip bool)
}
// copied from net/transport.go
// Modified to support Extended CONNECT:
// Contrary to what the godoc for the http.Request says,
// we do respect the Proto field if the method is CONNECT.
func (w *requestWriter) encodeHeaders(req *http.Request, addGzipHeader bool, trailers string, contentLength int64) error {
host := req.Host
if host == "" {
@@ -124,8 +126,11 @@ func (w *requestWriter) encodeHeaders(req *http.Request, addGzipHeader bool, tra
return err
}
// http.NewRequest sets this field to HTTP/1.1
isExtendedConnect := req.Method == http.MethodConnect && req.Proto != "" && req.Proto != "HTTP/1.1"
var path string
if req.Method != "CONNECT" {
if req.Method != http.MethodConnect || isExtendedConnect {
path = req.URL.RequestURI()
if !validPseudoPath(path) {
orig := path
@@ -162,10 +167,13 @@ func (w *requestWriter) encodeHeaders(req *http.Request, addGzipHeader bool, tra
// [RFC3986]).
f(":authority", host)
f(":method", req.Method)
if req.Method != "CONNECT" {
if req.Method != http.MethodConnect || isExtendedConnect {
f(":path", path)
f(":scheme", req.URL.Scheme)
}
if isExtendedConnect {
f(":protocol", req.Proto)
}
if trailers != "" {
f("trailer", trailers)
}