This commit is contained in:
gospider
2024-12-04 16:29:02 +08:00
parent 179dd44b56
commit 1e2ba7c4a6
11 changed files with 215 additions and 73 deletions

View File

@@ -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
}