forked from Greyh4t/zhttp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
145 lines (116 loc) · 4.97 KB
/
options.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
package zhttp
import (
"net/url"
"time"
)
type Auth struct {
Username string
Password string
}
type HttpOptions struct {
// UserAgent allows you to set an arbitrary custom user agent
// if ReqOptions.UserAgent or ReqOptions.Headers["User-Agent"] not empty, this option will be overwrite
UserAgent string
// Headers uses to set custom HTTP headers to every request
// Headers that are repeated with ReqOptions.Headers will be overwrite
Headers map[string]string
// Proxies is a map in the following format
// *protocol* => proxy address e.g http => http://127.0.0.1:8080
// effective on every request
Proxies map[string]*url.URL
// DisableRedirect will disable redirect for request
DisableRedirect bool
// InsecureSkipVerify is a flag that specifies if we should validate the
// server's TLS certificate. It should be noted that Go's TLS verify mechanism
// doesn't validate if a certificate has been revoked
InsecureSkipVerify bool
// Timeout is the maximum amount of time a whole request(include dial / request / redirect) will wait.
Timeout time.Duration
// Timeout is the maximum amount of time a dial will wait for a connect to complete.
DialTimeout time.Duration
// TLSHandshakeTimeout specifies the maximum amount of time waiting to
// wait for a TLS handshake. Zero means no timeout.
TLSHandshakeTimeout time.Duration
// KeepAlive specifies the interval between keep-alive
// probes for an active network connection.
// If zero, keep-alive probes are sent with a default value
// (currently 15 seconds), if supported by the protocol and operating
// system. Network protocols or operating systems that do
// not support keep-alives ignore this field.
// If negative, keep-alive probes are disabled.
KeepAlive time.Duration
// DisableKeepAlives, if true, disables HTTP keep-alives and
// will only use the connection to the server for a single
// HTTP request.
//
// This is unrelated to the similarly named TCP keep-alives.
DisableKeepAlives bool
// DisableCompression, if true, prevents the Transport from
// requesting compression with an "Accept-Encoding: gzip"
// request header when the Request contains no existing
// Accept-Encoding value. If the Transport requests gzip on
// its own and gets a gzipped response, it's transparently
// decoded in the Response.Body. However, if the user
// explicitly requested gzip it is not automatically
// uncompressed.
DisableCompression bool
// MaxIdleConns controls the maximum number of idle (keep-alive)
// connections across all hosts. Zero means no limit.
MaxIdleConns int
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
// (keep-alive) connections to keep per-host. If zero,
// DefaultMaxIdleConnsPerHost is used.
MaxIdleConnsPerHost int
// MaxConnsPerHost optionally limits the total number of
// connections per host, including connections in the dialing,
// active, and idle states. On limit violation, dials will block.
//
// Zero means no limit.
MaxConnsPerHost int
// IdleConnTimeout is the maximum amount of time an idle
// (keep-alive) connection will remain idle before closing
// itself.
// Zero means no limit.
IdleConnTimeout time.Duration
// DNSCacheExpire is the timeout of dns cache , if zero, not use dns cache
DNSCacheExpire time.Duration
// DNSServer allows you to set an custom dns host, like 1.1.1.1:25, only effective in linux
DNSServer string
}
type ReqOptions struct {
// Timeout is the maximum amount of time a whole request(include dial / request / redirect) will wait.
// if non-zero, overwrite HttpOptions.Timeout in current request
Timeout time.Duration
// ContentType allows you to set an arbitrary custom content type
ContentType string
// UserAgent allows you to set an arbitrary custom user agent
UserAgent string
// Proxies is a map in the following format
// *protocol* => proxy address e.g http => http://127.0.0.1:8080
// overwrite HttpOptions.Proxies in current request
Proxies map[string]*url.URL
// DisableRedirect will disable redirect for request
// if true or HttpOptions.DisableRedirect is true, will effective
DisableRedirect bool
// Query will be encode to query string that may be used within a GET request
Query Query
// Body is a interface{} that will eventually convert into the the body of a POST request.
Body Body
// Cookie is an struct that allows you to attach cookies to your request
// only effective in current request
Cookie Cookie
// Headers uses to set custom HTTP headers to the request
Headers map[string]string
// Host allows you to set an arbitrary custom host
Host string
// Hosts allows you to set an custom dns resolve value
// when proxy usable, this value does not take effect
Hosts string
// Auth allows you to specify a user name and password that you wish to
// use when requesting the URL. It will use basic HTTP authentication
// formatting the username and password in base64
Auth Auth
// IsAjax is a flag that can be set to make the request appear
// to be generated by browser Javascript
IsAjax bool
}