Skip to content

Commit

Permalink
fix: trailing NULL bytes in buffer while detecting a content type (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Mar 2, 2024
1 parent 97187c4 commit 0ac42a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func Test_parseRequestBody(t *testing.T) {
expectedContentLength: "744",
},
{
name: "mulipart fields",
name: "multipart fields",
init: func(c *Client, r *Request) {
r.SetMultipartFields(
&MultipartField{
Expand All @@ -776,15 +776,15 @@ func Test_parseRequestBody(t *testing.T) {
expectedContentLength: "344",
},
{
name: "mulipart files",
name: "multipart files",
init: func(c *Client, r *Request) {
r.SetFileReader("foo", "foo.txt", strings.NewReader("1")).
SetFileReader("bar", "bar.txt", strings.NewReader("2")).
SetContentLength(true)
},
expectedBodyBuf: []byte(`{"bar":"2","foo":"1"}`),
expectedContentType: "multipart/form-data; boundary=",
expectedContentLength: "412",
expectedContentLength: "414",
},
{
name: "body with errorReader",
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func writeMultipartFormFile(w *multipart.Writer, fieldName, fileName string, r i
return err
}

partWriter, err := w.CreatePart(createMultipartHeader(fieldName, fileName, http.DetectContentType(cbuf)))
partWriter, err := w.CreatePart(createMultipartHeader(fieldName, fileName, http.DetectContentType(cbuf[:size])))
if err != nil {
return err
}
Expand Down

0 comments on commit 0ac42a2

Please sign in to comment.