mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
14
requests.go
14
requests.go
@@ -35,6 +35,7 @@ type reqCtxData struct {
|
||||
forceHttp1 bool
|
||||
maxRedirect int
|
||||
proxy *url.URL
|
||||
proxys []*url.URL
|
||||
disProxy bool
|
||||
disAlive bool
|
||||
orderHeaders []string
|
||||
@@ -102,6 +103,16 @@ func NewReqCtxData(ctx context.Context, option *RequestOption) (*reqCtxData, err
|
||||
}
|
||||
ctxData.proxy = tempProxy
|
||||
}
|
||||
if l := len(option.Proxys); l > 0 {
|
||||
ctxData.proxys = make([]*url.URL, l)
|
||||
for i, proxy := range option.Proxys {
|
||||
tempProxy, err := gtls.VerifyProxy(proxy)
|
||||
if err != nil {
|
||||
return ctxData, tools.WrapError(errFatal, errors.New("tempRequest init proxy error"), err)
|
||||
}
|
||||
ctxData.proxys[i] = tempProxy
|
||||
}
|
||||
}
|
||||
return ctxData, nil
|
||||
}
|
||||
func CreateReqCtx(ctx context.Context, ctxData *reqCtxData) context.Context {
|
||||
@@ -271,6 +282,9 @@ func (obj *Client) request(ctx context.Context, option *RequestOption) (response
|
||||
if err != nil {
|
||||
return response, tools.WrapError(err, errors.New("tempRequest init headers error"), err)
|
||||
}
|
||||
if headers != nil && option.UserAgent != "" {
|
||||
headers.Set("User-Agent", option.UserAgent)
|
||||
}
|
||||
if orderHeaders == nil {
|
||||
orderHeaders = option.OrderHeaders
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user