-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathstructs.go
139 lines (100 loc) · 4.8 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
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"
"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
Header http.Header // Default headers for all requests. Deprecated: Use OrderedHeaders instead.
HeaderOrder HeaderOrder // Order of headers for all requests.
CookieJar *cookiejar.Jar // Stores cookies across session requests.
Browser string // Name or identifier of the browser used in the session.
Connections *ConnPool // Pool of persistent connections to manage concurrent requests.
HTTP2Transport *http2.Transport
Transport *http.Transport
GetClientHelloSpec func() *tls.ClientHelloSpec // Function to provide custom TLS handshake details.
mu *sync.Mutex
Proxy string // Proxy address.
H2Proxy bool // If true, use HTTP2 for proxy connections.
ProxyDialer *proxyDialer
proxyConnected bool
Verbose bool // If true, print detailed logs or debugging information.
VerbosePath string // Path for logging verbose information.
VerboseIgnoreHost []string // List of hosts to ignore when logging verbose info.
VerboseFunc func(request *Request, response *Response, err error) // Custom function to handle verbose logging.
MaxRedirects uint // Maximum number of redirects to follow.
TimeOut time.Duration // Maximum time to wait for request to complete.
PreHook func(request *Request) error // Function called before sending request.
Callback func(request *Request, response *Response, err error) // Function called after receiving a response.
// Deprecated: This field is ignored as pin verification is always true.
// To disable pin verification, use InsecureSkipVerify.
VerifyPins bool
InsecureSkipVerify bool // If true, server's certificate is not verified.
ctx context.Context // Context for cancellable and timeout operations.
UserAgent string // Headers for User-Agent and Sec-Ch-Ua, respectively.
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
ContentLength int64 // Length of content in the request.
ctx context.Context // Context for cancellable and timeout operations.
}
// 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.
}