|
|
|
@ -39,6 +39,7 @@ type Request struct {
|
|
|
|
|
RespHeader http.Header
|
|
|
|
|
RespCookies []*http.Cookie
|
|
|
|
|
RespHttpCode int
|
|
|
|
|
Location *url.URL
|
|
|
|
|
CircleBuffer *stario.StarBuffer
|
|
|
|
|
respReader io.ReadCloser
|
|
|
|
|
RequestOpts
|
|
|
|
@ -57,6 +58,7 @@ type RequestOpts struct {
|
|
|
|
|
SkipTLSVerify bool
|
|
|
|
|
CustomTransport *http.Transport
|
|
|
|
|
Queries map[string]string
|
|
|
|
|
DisableRedirect bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type RequestOpt func(opt *RequestOpts)
|
|
|
|
@ -167,6 +169,12 @@ func WithSkipTLSVerify(skip bool) RequestOpt {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithDisableRedirect(disable bool) RequestOpt {
|
|
|
|
|
return func(opt *RequestOpts) {
|
|
|
|
|
opt.DisableRedirect = disable
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewRequests(url string, rawdata []byte, method string, opts ...RequestOpt) Request {
|
|
|
|
|
req := Request{
|
|
|
|
|
RequestOpts: RequestOpts{
|
|
|
|
@ -292,6 +300,7 @@ func Curl(curl Request) (resps Request, err error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return Request{}, err
|
|
|
|
|
}
|
|
|
|
|
curl.Location, _ = resp.Location()
|
|
|
|
|
curl.RespHttpCode = resp.StatusCode
|
|
|
|
|
curl.RespHeader = resp.Header
|
|
|
|
|
curl.RespCookies = resp.Cookies()
|
|
|
|
@ -387,6 +396,11 @@ func netcurl(curl Request) (*http.Response, error) {
|
|
|
|
|
client := &http.Client{
|
|
|
|
|
Transport: curl.CustomTransport,
|
|
|
|
|
}
|
|
|
|
|
if curl.DisableRedirect {
|
|
|
|
|
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
|
|
|
|
return http.ErrUseLastResponse
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
|
return resp, err
|
|
|
|
|
}
|
|
|
|
|