forked from Noooste/azuretls-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructs.go
186 lines (139 loc) · 5.24 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
package azuretls
import (
"context"
http "github.com/Noooste/fhttp"
"github.com/Noooste/fhttp/cookiejar"
"github.com/Noooste/fhttp/http2"
tls "github.com/Noooste/utls"
"io"
"net/url"
"regexp"
"sync"
"time"
)
const (
Path = ":path"
Method = ":method"
Authority = ":authority"
Scheme = ":scheme"
)
// 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
mu *sync.Mutex
// Proxy address.
Proxy string
// If true, use HTTP2 for proxy connections.
H2Proxy bool
ProxyDialer *proxyDialer
proxyConnected bool
dump bool
dumpDir string
dumpIgnore []*regexp.Regexp
logging bool
loggingIgnore []string
// 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)
// 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
// Context for cancellable and timeout operations.
ctx context.Context
// Headers for User-Agent and Sec-Ch-Ua, respectively.
UserAgent string
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
Method string // HTTP method, e.g., GET, POST.
Url string
parsedUrl *url.URL // Parsed version of Url.
Body any
body []byte
PHeader PHeader
OrderedHeaders OrderedHeaders
Header http.Header // Headers for the request. Deprecated: Use OrderedHeaders instead.
HeaderOrder HeaderOrder // Order of headers for the request.
conn *Conn // Connection associated with the request.
proxy string
ua string
browser string
DisableRedirects bool // If true, redirects won't be followed.
MaxRedirects uint // Maximum number of redirects to follow.
NoCookie bool // If true, cookies won't be included in the request.
TimeOut time.Duration // Maximum time to wait for request to complete.
IsRedirected bool // Indicates if the current request is a result of a redirection.
InsecureSkipVerify bool // If true, server's certificate is not verified.
IgnoreBody bool // If true, the body of the response is not read.
Proto string
ForceHTTP1 bool
ContentLength int64 // Length of content in the request.
ctx context.Context // Context for cancellable and timeout operations.
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 {
StatusCode int // HTTP status code, e.g., 200, 404.
Body []byte // Byte representation of the response body.
RawBody io.ReadCloser // Raw body stream.
Header http.Header // Response headers.
Cookies map[string]string // Parsed cookies from the response.
Url string // URL from which the response was received.
IgnoreBody bool // Indicates if the body of the response was ignored.
HttpResponse *http.Response // The underlying HTTP response.
Request *Request // Reference to the associated request.
ContentLength int64 // Length of content in the response.
}
type Context struct {
Session *Session
Request *Request
Response *Response
Err error
RequestStartTime time.Time
}