forked from saucesteals/mimic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mimic.go
60 lines (47 loc) · 1.54 KB
/
mimic.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
package mimic
import (
"log"
utls "github.com/refraction-networking/utls"
http "github.com/saucesteals/fhttp"
"github.com/saucesteals/fhttp/http2"
)
type ClientSpec struct {
version string
clientHintUA string
HTTP2Options *HTTP2Options
GetTlsSpec func() *utls.ClientHelloSpec
}
type HTTP2Options struct {
Settings []http2.Setting
PseudoHeaderOrder []string
MaxHeaderListSize uint32
InitialWindowSize uint32
HeaderTableSize uint32
}
// ConfigureTransport configures a http.Transport to follow the client's spec
// Returns the given Transport for convenience
func (c *ClientSpec) ConfigureTransport(t1 *http.Transport) *http.Transport {
t1.GetTlsClientHelloSpec = c.GetTlsSpec
t2, err := http2.ConfigureTransports(t1)
if err != nil {
log.Printf("error enabling Transport HTTP/2 support: %v", err)
return t1
}
t2.Settings = c.HTTP2Options.Settings
t2.MaxHeaderListSize = c.HTTP2Options.MaxHeaderListSize
t2.InitialWindowSize = c.HTTP2Options.MaxHeaderListSize
t2.HeaderTableSize = c.HTTP2Options.MaxHeaderListSize
return t1
}
// Version returns the version for the mimicked client..
func (c *ClientSpec) Version() string {
return c.version
}
// ClientHintUA returns the "sec-ch-ua" header value for the mimicked client.
func (c *ClientSpec) ClientHintUA() string {
return c.clientHintUA
}
// PseudoHeaderOrder returns the pseudo header order for the mimicked client.
func (c *ClientSpec) PseudoHeaderOrder() []string {
return c.HTTP2Options.PseudoHeaderOrder
}