-
Notifications
You must be signed in to change notification settings - Fork 63
/
http.go
93 lines (82 loc) · 2.56 KB
/
http.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package phttp
import (
"github.com/pkg/errors"
"go.uber.org/zap"
)
type GunConfig struct {
Client ClientConfig `config:",squash"`
Target string `validate:"endpoint,required"`
TargetResolved string `config:"-"`
SSL bool
AutoTag AutoTagConfig `config:"auto-tag"`
AnswLog AnswLogConfig `config:"answlog"`
HTTPTrace HTTPTraceConfig `config:"httptrace"`
SharedClient struct {
ClientNumber int `config:"client-number,omitempty"`
Enabled bool `config:"enabled"`
} `config:"shared-client,omitempty"`
}
func NewHTTP1Gun(cfg GunConfig, answLog *zap.Logger) *BaseGun {
return NewBaseGun(HTTP1ClientConstructor, cfg, answLog)
}
func HTTP1ClientConstructor(clientConfig ClientConfig, target string) Client {
transport := NewTransport(clientConfig.Transport, NewDialer(clientConfig.Dialer).DialContext, target)
client := NewRedirectingClient(transport, clientConfig.Redirect)
return client
}
var _ ClientConstructor = HTTP1ClientConstructor
// NewHTTP2Gun return simple HTTP/2 gun that can shoot sequentially through one connection.
func NewHTTP2Gun(cfg GunConfig, answLog *zap.Logger) (*BaseGun, error) {
if !cfg.SSL {
// Open issue on github if you really need this feature.
return nil, errors.New("HTTP/2.0 over TCP is not supported. Please leave SSL option true by default.")
}
return NewBaseGun(HTTP2ClientConstructor, cfg, answLog), nil
}
func HTTP2ClientConstructor(clientConfig ClientConfig, target string) Client {
transport := NewHTTP2Transport(clientConfig.Transport, NewDialer(clientConfig.Dialer).DialContext, target)
client := NewRedirectingClient(transport, clientConfig.Redirect)
// Will panic and cancel shooting whet target doesn't support HTTP/2.
return &panicOnHTTP1Client{Client: client}
}
var _ ClientConstructor = HTTP2ClientConstructor
func DefaultHTTPGunConfig() GunConfig {
return GunConfig{
SSL: false,
Client: DefaultClientConfig(),
AutoTag: AutoTagConfig{
Enabled: false,
URIElements: 2,
NoTagOnly: true,
},
AnswLog: AnswLogConfig{
Enabled: false,
Path: "answ.log",
Filter: "error",
},
HTTPTrace: HTTPTraceConfig{
DumpEnabled: false,
TraceEnabled: false,
},
}
}
func DefaultHTTP2GunConfig() GunConfig {
return GunConfig{
Client: DefaultClientConfig(),
AutoTag: AutoTagConfig{
Enabled: false,
URIElements: 2,
NoTagOnly: true,
},
AnswLog: AnswLogConfig{
Enabled: false,
Path: "answ.log",
Filter: "error",
},
HTTPTrace: HTTPTraceConfig{
DumpEnabled: false,
TraceEnabled: false,
},
SSL: true,
}
}