I'm try send HTTP/2 request from Go, but I can't.
client := &net.Client{}
request, err := net.NewRequest("GET", someUrl, nil)
if err != nil {
return "", err
}
// some headers
// some cookies
client.Transport = &http2.Transport{}
response, err := client.Do(request)
If I print dump request
dr, _ := httputil.DumpRequest(request, false)
fmt.Println(string(dr))
Then it turns out the following
GET /some/url HTTP/1.1
// some headers
// some cookies
Why?
CodePudding user response:
I'm try send HTTP/2 request from Go, but I can't. ...
dr, _ := httputil.DumpRequest(request, false) fmt.Println(string(dr))
Then it turns out the following
GET /some/url HTTP/1.1 // some headers // some cookies
DumpRequest will not print the request as sent on the wire and is specifically not suitable for checking if HTTP/2 is used. The documentation explicitly states:
DumpRequest returns the given request in its HTTP/1.x wire representation. It should only be used by servers to debug client requests. The returned representation is an approximation only; some details of the initial request are lost while parsing it into an http.Request. In particular, the order and case of header field names are lost. The order of values in multi-valued headers is kept intact. HTTP/2 requests are dumped in HTTP/1.x form, not in their original binary representations."