-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtransport.go
71 lines (56 loc) · 1.44 KB
/
transport.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package azuretls
import (
http "github.com/Noooste/fhttp"
"github.com/Noooste/fhttp/http2"
"time"
)
func (s *Session) InitTransport(browser string) (err error) {
s.mu.Lock()
defer s.mu.Unlock()
if s.Transport == nil {
s.initHTTP1()
}
if s.HTTP2Transport == nil {
if err = s.initHTTP2(browser); err != nil {
return
}
}
return
}
func (s *Session) initHTTP1() {
s.Transport = &http.Transport{
TLSHandshakeTimeout: s.TimeOut,
ResponseHeaderTimeout: s.TimeOut,
DialTLSContext: s.dialTLS,
DialContext: s.dial,
MaxIdleConns: 1e3,
IdleConnTimeout: 90 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
}
func (s *Session) initHTTP2(browser string) error {
tr, err := http2.ConfigureTransports(s.Transport) // upgrade to HTTP2, while keeping http.Transport
if err != nil {
return err
}
tr.Priorities = defaultStreamPriorities(browser)
tr.Settings, tr.SettingsOrder = defaultHeaderSettings(browser)
tr.ConnectionFlow = defaultWindowsUpdate(browser)
if s.HeaderPriority != nil {
tr.HeaderPriority = s.HeaderPriority
} else {
tr.HeaderPriority = defaultHeaderPriorities(browser)
}
tr.StrictMaxConcurrentStreams = true
tr.PushHandler = &http2.DefaultPushHandler{}
for k, v := range tr.Settings {
switch k {
case http2.SettingInitialWindowSize:
tr.InitialWindowSize = v
case http2.SettingHeaderTableSize:
tr.HeaderTableSize = v
}
}
s.HTTP2Transport = tr
return nil
}