-
Notifications
You must be signed in to change notification settings - Fork 25
/
structs.go
258 lines (204 loc) · 7.37 KB
/
structs.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package azuretls
import (
"context"
"errors"
http "github.com/Noooste/fhttp"
"github.com/Noooste/fhttp/cookiejar"
"github.com/Noooste/fhttp/http2"
tls "github.com/Noooste/utls"
"io"
"net"
"net/url"
"regexp"
"sync"
"time"
)
const (
Path = ":path"
Method = ":method"
Authority = ":authority"
Scheme = ":scheme"
)
var ErrUseLastResponse = errors.New("azuretls: use last response")
// Session represents the core structure for managing and conducting HTTP(S)
// sessions. It holds configuration settings, headers, cookie storage,
// connection pool, and other attributes necessary to perform and customize
// requests.
type Session struct {
PHeader PHeader
OrderedHeaders OrderedHeaders
// Default headers for all requests. Deprecated: Use OrderedHeaders instead.
Header http.Header
// Order of headers for all requests.
HeaderOrder HeaderOrder
// Stores cookies across session requests.
CookieJar *cookiejar.Jar
// Name or identifier of the browser used in the session.
Browser string
// Pool of persistent connections to manage concurrent requests.
Connections *ConnPool
HTTP2Transport *http2.Transport
Transport *http.Transport
// Function to provide custom TLS handshake details.
GetClientHelloSpec func() *tls.ClientHelloSpec
// Proxy address.
Proxy string
// If true, use HTTP2 for proxy connections.
H2Proxy bool
ProxyDialer *proxyDialer
// If true, print detailed logs or debugging information. Deprecated: Use Dump instead.
Verbose bool
// Path for logging verbose information. Deprecated: Use Log instead.
VerbosePath string
// List of hosts to ignore when logging verbose info. Deprecated: Use Log instead.
VerboseIgnoreHost []string
// Custom function to handle verbose logging. Deprecated: Use Log instead.
VerboseFunc func(request *Request, response *Response, err error)
// Maximum number of redirects to follow.
MaxRedirects uint
// Maximum time to wait for request to complete.
TimeOut time.Duration
// Deprecated, use PreHookWithContext instead.
PreHook func(request *Request) error
// Function called before sending a request.
PreHookWithContext func(ctx *Context) error
// Deprecated, use CallbackWithContext instead.
Callback func(request *Request, response *Response, err error)
// Function called after receiving a response.
CallbackWithContext func(ctx *Context)
// Function to modify the dialer used for establishing connections.
ModifyDialer func(dialer *net.Dialer) error
// CheckRedirect specifies the policy for handling redirects.
// If CheckRedirect is not nil, the client calls it before
// following an HTTP redirect. The arguments req and via are
// the upcoming request and the requests made already, oldest
// first. If CheckRedirect returns an error, the Session's Get
// method returns both the previous Response (with its Body
// closed) and CheckRedirect's error (wrapped in an url.Error)
// instead of issuing the Request req.
// As a special case, if CheckRedirect returns ErrUseLastResponse,
// then the most recent response is returned, along with a nil error.
//
// If CheckRedirect is nil, the Session uses its default policy,
// which is to stop after 10 consecutive requests.
CheckRedirect func(req *Request, reqs []*Request) error
// Deprecated: This field is ignored as pin verification is always true.
// To disable pin verification, use InsecureSkipVerify.
VerifyPins bool
// If true, server's certificate is not verified (insecure: this may facilitate attack from middleman).
InsecureSkipVerify bool
// Headers for User-Agent and Sec-Ch-Ua, respectively.
UserAgent string
// HeaderPriority specifies the priority of the request's headers.
// As this information is not included in the Akamai fingerprint, you may have to specify it manually.
// Note that you can also specify the browser in the session so that this is done automatically.
HeaderPriority *http2.PriorityParam
// ProxyHeader defines the headers used for the CONNECT method to the proxy,
// you may define the order with the http.HeaderOrderKey
ProxyHeader http.Header
proxyConnected bool
dump bool
dumpDir string
dumpIgnore []*regexp.Regexp
logging bool
loggingIgnore []*regexp.Regexp
ctx context.Context
mu *sync.Mutex
closed bool
}
// Request represents the details and configuration for an individual HTTP(S)
// request. It encompasses URL, headers, method, body, proxy settings,
// timeouts, and other configurations necessary for customizing the request
// and its execution.
type Request struct {
HttpRequest *http.Request
Response *Response
// HTTP method, e.g., GET, POST.
Method string
Url string
// Parsed version of Url.
parsedUrl *url.URL
Body any
body []byte
PHeader PHeader
OrderedHeaders OrderedHeaders
// Headers for the request. Deprecated: Use OrderedHeaders instead.
Header http.Header
// Order of headers for the request.
HeaderOrder HeaderOrder
// Connection associated with the request.
conn *Conn
proxy string
ua string
browser string
// If true, redirects won't be followed.
DisableRedirects bool
// Maximum number of redirects to follow.
MaxRedirects uint
// If true, cookies won't be included in the request.
NoCookie bool
// Maximum time to wait for request to complete.
TimeOut time.Duration
// Indicates if the current request is a result of a redirection.
IsRedirected bool
// If true, server's certificate is not verified.
InsecureSkipVerify bool
// If true, the body of the response is not read.
// The response body can be read from Response.RawBody and
// you will have to close using Response.CloseBody manually.
IgnoreBody bool
Proto string
ForceHTTP1 bool
// Length of content in the request.
ContentLength int64
// Context for cancellable and timeout operations.
ctx context.Context
startTime time.Time
deadline time.Time
}
// Response encapsulates the received data and metadata from an HTTP(S)
// request. This includes status code, body, headers, cookies, associated
// request details, TLS connection state, etc.
type Response struct {
// HTTP status code, e.g., 200, 404.
StatusCode int
// HTTP status message, e.g., "OK", "Not Found".
Status string
// Byte representation of the response body.
Body []byte
// Raw body stream.
RawBody io.ReadCloser
// Response headers.
Header http.Header
// Parsed cookies from the response.
Cookies map[string]string
// URL from which the response was received.
Url string
// Indicates if the body of the response was ignored.
IgnoreBody bool
// The underlying HTTP response.
HttpResponse *http.Response
// Reference to the associated request.
Request *Request
// Length of content in the response.
ContentLength int64
Session *Session
}
// Context represents the context of a request. It holds the session, request,
// response, error, and other details associated with the request.
type Context struct {
// Session is the session associated with the request.
Session *Session
// Request is the request being made.
Request *Request
// Response is the response received.
// It can be modified to change the response returned by the request.
Response *Response
// Err is the error, if any, that occurred during the request.
// It can be modified to change the error returned by the request.
Err error
// Ctx is the context associated with the request.
ctx context.Context
// RequestStartTime is the time when the request was started.
RequestStartTime time.Time
}