http2 icon indicating copy to clipboard operation
http2 copied to clipboard

how to enable http2

Open KazumiLine opened this issue 2 years ago • 0 comments

i tried the example code of client, but the resp.Header.Protocol() returns HTTP/1.1 could you help me use http2 client?

hc := &fasthttp.HostClient{
	Addr: "api.binance.com:443",
}

if err := fasthttp2.ConfigureClient(hc, fasthttp2.ClientOpts{}); err != nil {
	log.Printf("%s doesn't support http/2\n", hc.Addr)
}
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
req.SetRequestURI("https://api.binance.com/api/v3/time")
req.Header.SetMethod("GET")
err := hc.Do(req, resp)
if err != nil {
	log.Fatalln(err)
}
fmt.Println(resp)
fmt.Printf("%d: %s, %s\n", resp.StatusCode(), resp.Body(), resp.Header.Protocol())

KazumiLine avatar Nov 14 '22 12:11 KazumiLine