mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
22
option.go
22
option.go
@@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
@@ -115,7 +114,7 @@ func randomBoundary() string {
|
||||
|
||||
func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
if obj.Body != nil {
|
||||
body, orderData, _, err := obj.newBody(obj.Body)
|
||||
body, orderData, err := obj.newBody(obj.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -131,13 +130,10 @@ func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
if obj.ContentType == "" {
|
||||
obj.ContentType = randomBoundary()
|
||||
}
|
||||
body, orderData, ok, err := obj.newBody(obj.Form)
|
||||
body, orderData, err := obj.newBody(obj.Form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, errors.New("not support type")
|
||||
}
|
||||
if body != nil {
|
||||
return body, nil
|
||||
}
|
||||
@@ -151,13 +147,10 @@ func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
if obj.ContentType == "" {
|
||||
obj.ContentType = "application/x-www-form-urlencoded"
|
||||
}
|
||||
body, orderData, ok, err := obj.newBody(obj.Data)
|
||||
body, orderData, err := obj.newBody(obj.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, errors.New("not support type")
|
||||
}
|
||||
if body != nil {
|
||||
return body, nil
|
||||
}
|
||||
@@ -166,7 +159,7 @@ func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
if obj.ContentType == "" {
|
||||
obj.ContentType = "application/json"
|
||||
}
|
||||
body, orderData, _, err := obj.newBody(obj.Json)
|
||||
body, orderData, err := obj.newBody(obj.Json)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -178,7 +171,7 @@ func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
if obj.ContentType == "" {
|
||||
obj.ContentType = "text/plain"
|
||||
}
|
||||
body, orderData, _, err := obj.newBody(obj.Text)
|
||||
body, orderData, err := obj.newBody(obj.Text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -195,13 +188,10 @@ func (obj *RequestOption) initParams() (*url.URL, error) {
|
||||
if obj.Params == nil {
|
||||
return baseUrl, nil
|
||||
}
|
||||
body, dataData, ok, err := obj.newBody(obj.Params)
|
||||
body, dataData, err := obj.newBody(obj.Params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, errors.New("not support type")
|
||||
}
|
||||
var query string
|
||||
if body != nil {
|
||||
paramsBytes, err := io.ReadAll(body)
|
||||
|
||||
Reference in New Issue
Block a user