Hi,
I'm trying to understand why in the following code, client2 doesn't work
'http2_handshake_failed" error)
According
from
https://pkg.go.dev/net/http#pkg-overview:~:text=Starting%20with%20Go,are%20currently%20supported%3A
,it's the way to disable HTTP/2.
thx
...
package main
import (
"crypto/tls"
"fmt"
"net/http"
"time"
)
func main() {
// client1, disable HTTP/2
httpClient1 := &http.Client{
Transport: &http.Transport{
TLSNextProto: map[string]func(string, *tls.Conn)
http.RoundTripper{},
},
}
// client2, clone default transport, disable HTTP/2
var netTransport = http.DefaultTransport.(*http.Transport).Clone()
netTransport.TLSNextProto = map[string]func(string, *tls.Conn)
http.RoundTripper{}
netTransport.ForceAttemptHTTP2 = false
httpClient2 := &http.Client{
Transport: netTransport,
}
doClient(httpClient1)
doClient(httpClient2)
}
func doClient(client *http.Client) {
resp, err := client.Get("https://google.com/")
if err != nil {
fmt.Printf("client error : %s\n", err)
} else {
defer resp.Body.Close()
fmt.Printf("Response status: %s with protocol %s\n", resp.Status,
resp.Proto)
}
}
...
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/a8a0d556-1758-4ac9-94d4-77fc9b338bf9n%40googlegroups.com.