mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
3
body.go
3
body.go
@@ -247,7 +247,7 @@ func (obj *OrderData) parseParams() *bytes.Buffer {
|
||||
}
|
||||
return buf
|
||||
}
|
||||
func (obj *OrderData) parseForm(ctx context.Context) (io.Reader, bool, error) {
|
||||
func (obj *OrderData) parseForm(ctx context.Context, boundary string) (io.Reader, bool, error) {
|
||||
if len(obj.data) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
@@ -265,6 +265,7 @@ func (obj *OrderData) parseForm(ctx context.Context) (io.Reader, bool, error) {
|
||||
}
|
||||
body := bytes.NewBuffer(nil)
|
||||
writer := multipart.NewWriter(body)
|
||||
writer.SetBoundary(boundary)
|
||||
err := obj.formWriteMain(writer)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
|
||||
@@ -102,14 +102,14 @@ type File struct {
|
||||
ContentType string
|
||||
}
|
||||
|
||||
func randomBoundary() string {
|
||||
func randomBoundary() (string, string) {
|
||||
var buf [30]byte
|
||||
io.ReadFull(rand.Reader, buf[:])
|
||||
boundary := fmt.Sprintf("%x", buf[:])
|
||||
if strings.ContainsAny(boundary, `()<>@,;:\"/[]?= `) {
|
||||
boundary = `"` + boundary + `"`
|
||||
}
|
||||
return "multipart/form-data; boundary=" + boundary
|
||||
return "multipart/form-data; boundary=" + boundary, boundary
|
||||
}
|
||||
|
||||
func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
@@ -127,8 +127,9 @@ func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
}
|
||||
return bytes.NewReader(con), nil
|
||||
} else if obj.Form != nil {
|
||||
var boundary string
|
||||
if obj.ContentType == "" {
|
||||
obj.ContentType = randomBoundary()
|
||||
obj.ContentType, boundary = randomBoundary()
|
||||
}
|
||||
body, orderData, err := obj.newBody(obj.Form)
|
||||
if err != nil {
|
||||
@@ -137,7 +138,7 @@ func (obj *RequestOption) initBody(ctx context.Context) (io.Reader, error) {
|
||||
if body != nil {
|
||||
return body, nil
|
||||
}
|
||||
body, once, err := orderData.parseForm(ctx)
|
||||
body, once, err := orderData.parseForm(ctx, boundary)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user