forked from pubnub/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients.go
40 lines (33 loc) · 1.09 KB
/
clients.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
35
36
37
38
39
40
package pubnub
import (
"golang.org/x/net/http2"
"net"
"net/http"
"time"
)
// NewHTTP1Client creates a new HTTP 1 client with a new transport initialized with connect and read timeout
func NewHTTP1Client(connectTimeout, responseReadTimeout, maxIdleConnsPerHost int) *http.Client {
transport := &http.Transport{
Dial: (&net.Dialer{
// Covers establishing a new TCP connection
Timeout: time.Duration(connectTimeout) * time.Second,
}).Dial,
MaxIdleConnsPerHost: maxIdleConnsPerHost,
}
client := &http.Client{
Transport: transport,
// Covers the entire exchange from Dial to reading the body
Timeout: time.Duration(responseReadTimeout) * time.Second,
}
return client
}
// NewHTTP2Client creates a new HTTP 2 client with a new transport initialized with connect and read timeout
func NewHTTP2Client(connectTimeout int, responseReadTimeout int) *http.Client {
transport := &http2.Transport{}
client := &http.Client{
Transport: transport,
// Covers the entire exchange from Dial to reading the body
Timeout: time.Duration(responseReadTimeout) * time.Second,
}
return client
}