Skip to content

Commit 0ac42a2

Browse files
authored
fix: trailing NULL bytes in buffer while detecting a content type (#779)
1 parent 97187c4 commit 0ac42a2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

middleware_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ func Test_parseRequestBody(t *testing.T) {
756756
expectedContentLength: "744",
757757
},
758758
{
759-
name: "mulipart fields",
759+
name: "multipart fields",
760760
init: func(c *Client, r *Request) {
761761
r.SetMultipartFields(
762762
&MultipartField{
@@ -776,15 +776,15 @@ func Test_parseRequestBody(t *testing.T) {
776776
expectedContentLength: "344",
777777
},
778778
{
779-
name: "mulipart files",
779+
name: "multipart files",
780780
init: func(c *Client, r *Request) {
781781
r.SetFileReader("foo", "foo.txt", strings.NewReader("1")).
782782
SetFileReader("bar", "bar.txt", strings.NewReader("2")).
783783
SetContentLength(true)
784784
},
785785
expectedBodyBuf: []byte(`{"bar":"2","foo":"1"}`),
786786
expectedContentType: "multipart/form-data; boundary=",
787-
expectedContentLength: "412",
787+
expectedContentLength: "414",
788788
},
789789
{
790790
name: "body with errorReader",

util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func writeMultipartFormFile(w *multipart.Writer, fieldName, fileName string, r i
216216
return err
217217
}
218218

219-
partWriter, err := w.CreatePart(createMultipartHeader(fieldName, fileName, http.DetectContentType(cbuf)))
219+
partWriter, err := w.CreatePart(createMultipartHeader(fieldName, fileName, http.DetectContentType(cbuf[:size])))
220220
if err != nil {
221221
return err
222222
}

0 commit comments

Comments
 (0)