diff --git a/protocol/httphelper.go b/protocol/httphelper.go index 6dbf7f4..fbbffe1 100644 --- a/protocol/httphelper.go +++ b/protocol/httphelper.go @@ -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) {