Skip to content

Commit cbdb783

Browse files
authored
Merge pull request #278 from vulncheck-oss/multipart
Add protocol.MultipartAddPart
2 parents 1ca77f7 + 9f33201 commit cbdb783

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

protocol/httphelper.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,22 +481,29 @@ func MultipartAddField(writer *multipart.Writer, name string, value string) bool
481481
return err == nil
482482
}
483483

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

491490
fw, err := writer.CreatePart(h)
492491
if err != nil {
493492
return false
494493
}
495-
_, err = io.Copy(fw, strings.NewReader(value))
494+
_, err = io.Copy(fw, strings.NewReader(body))
496495

497496
return err == nil
498497
}
499498

499+
func MultipartAddFile(writer *multipart.Writer, name, filename, ctype, value string) bool {
500+
// CreateFormFile doesn't expose Content-Type
501+
return MultipartAddPart(writer, map[string]string{
502+
"Content-Disposition": fmt.Sprintf(`form-data; name="%s"; filename="%s"`, name, filename),
503+
"Content-Type": ctype,
504+
}, value)
505+
}
506+
500507
// Provided an HTTP request, find the Set-Cookie headers, and extract
501508
// the value of the specified cookie. Example:.
502509
func GetSetCookieValue(resp *http.Response, name string) (string, bool) {

0 commit comments

Comments
 (0)