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
19 changes: 13 additions & 6 deletions protocol/httphelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,22 +481,29 @@ func MultipartAddField(writer *multipart.Writer, name string, value string) bool
return err == nil
}

func MultipartAddFile(writer *multipart.Writer, name, filename, ctype, value string) bool {
// CreateFormFile doesn't expose Content-Type
func MultipartAddPart(writer *multipart.Writer, headers map[string]string, body string) bool {
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition",
fmt.Sprintf(`form-data; name="%s"; filename="%s"`, name, filename))
h.Set("Content-Type", ctype)
for k, v := range headers {
h.Set(k, v)
}

fw, err := writer.CreatePart(h)
if err != nil {
return false
}
_, err = io.Copy(fw, strings.NewReader(value))
_, err = io.Copy(fw, strings.NewReader(body))

return err == nil
}

func MultipartAddFile(writer *multipart.Writer, name, filename, ctype, value string) bool {
// CreateFormFile doesn't expose Content-Type
return MultipartAddPart(writer, map[string]string{
"Content-Disposition": fmt.Sprintf(`form-data; name="%s"; filename="%s"`, name, filename),
"Content-Type": ctype,
}, value)
}

// Provided an HTTP request, find the Set-Cookie headers, and extract
// the value of the specified cookie. Example:.
func GetSetCookieValue(resp *http.Response, name string) (string, bool) {
Expand Down
Loading