mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
11
body.go
11
body.go
@@ -183,14 +183,7 @@ func (obj *OrderData) MarshalJSON() ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
key, err := gson.Encode(value.key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err = buf.Write(key); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = buf.WriteByte(':'); err != nil {
|
||||
if _, err = buf.WriteString(`"` + value.key + `":`); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
val, err := gson.Encode(value.val)
|
||||
@@ -211,7 +204,7 @@ func (obj *RequestOption) newBody(val any) (io.Reader, *OrderData, bool, error)
|
||||
case *OrderData:
|
||||
return nil, value, true, nil
|
||||
case io.Reader:
|
||||
obj.once = true
|
||||
obj.readOne = true
|
||||
return value, nil, true, nil
|
||||
case string:
|
||||
return bytes.NewReader(tools.StringToBytes(value)), nil, true, nil
|
||||
|
||||
@@ -90,7 +90,7 @@ type RequestOption struct {
|
||||
ClientOption
|
||||
Stream bool //disable auto read
|
||||
DisProxy bool //force disable proxy
|
||||
once bool
|
||||
readOne bool
|
||||
orderHeaders *OrderData //order headers
|
||||
gospiderSpec *GospiderSpec
|
||||
disBody bool
|
||||
@@ -145,7 +145,7 @@ func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
obj.once = once
|
||||
obj.readOne = once
|
||||
return body, err
|
||||
} else if obj.Data != nil {
|
||||
if obj.ContentType == "" {
|
||||
|
||||
@@ -119,7 +119,7 @@ func (obj *Client) Trace(ctx context.Context, href string, options ...RequestOpt
|
||||
// Define a function named Request that takes in four parameters:
|
||||
func (obj *Client) retryRequest(ctx context.Context, option RequestOption, uhref *url.URL, requestId string) (response *Response, err error) {
|
||||
defer func() {
|
||||
if errors.Is(err, errFatal) || response.Option().once {
|
||||
if errors.Is(err, errFatal) || response.Option().readOne {
|
||||
response.Option().MaxRetries = -1
|
||||
}
|
||||
}()
|
||||
@@ -145,7 +145,7 @@ func (obj *Client) retryRequest(ctx context.Context, option RequestOption, uhref
|
||||
response.Close()
|
||||
switch response.StatusCode() {
|
||||
case 307, 308:
|
||||
if response.Option().once {
|
||||
if response.Option().readOne {
|
||||
return
|
||||
}
|
||||
response = obj.newResponse(ctx, option, loc, requestId)
|
||||
|
||||
Reference in New Issue
Block a user