-
Notifications
You must be signed in to change notification settings - Fork 6
/
http2.go
34 lines (30 loc) · 804 Bytes
/
http2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package http2
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
"time"
"golang.org/x/net/http2"
)
// GetClient creates a http client use h2c
func GetClient() *http.Client {
return &http.Client{
Transport: &http2.Transport{
AllowHTTP: true,
DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) {
// If you're also using this client for non-h2c traffic, you may want to
// delegate to tls.Dial if the network isn't TCP or the addr isn't in an
// allow-list.
return net.Dial(network, addr)
},
PingTimeout: 30 * time.Second,
ReadIdleTimeout: 30 * time.Second,
},
}
}
// GetURL create a http connection address
func GetURL(host string, port int) string {
return fmt.Sprintf("https://%s:%d", host, port)
}