Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions net/gclient/gclient_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bytes"
"context"
"io"
"mime"
"mime/multipart"
"net/http"
"os"
Expand Down Expand Up @@ -172,7 +173,12 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data ..
allowFileUploading = true
)
if len(data) > 0 {
switch c.header[httpHeaderContentType] {
mediaType, _, err := mime.ParseMediaType(c.header[httpHeaderContentType])
if err != nil {
// Fallback: use the raw header value if parsing fails.
mediaType = c.header[httpHeaderContentType]
}
switch mediaType {
case httpHeaderContentTypeJson:
switch data[0].(type) {
case string, []byte:
Expand Down Expand Up @@ -206,7 +212,12 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data ..
if method == http.MethodGet {
var bodyBuffer *bytes.Buffer
if params != "" {
switch c.header[httpHeaderContentType] {
mediaType, _, err := mime.ParseMediaType(c.header[httpHeaderContentType])
if err != nil {
// Fallback: use the raw header value if parsing fails.
mediaType = c.header[httpHeaderContentType]
}
switch mediaType {
case
httpHeaderContentTypeJson,
httpHeaderContentTypeXml:
Expand Down
Loading