Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trailing NULL bytes in buffer while detecting a content type #779

Merged
merged 1 commit into from Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions middleware_test.go
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
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