net.http: allow custom headers in post_multipart_form (#11971)

pull/11975/head
Miccah 2021-09-25 02:09:49 -05:00 committed by GitHub
parent 4fbf3fdf03
commit 956fdffd96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -80,18 +80,23 @@ pub fn post_form(url string, data map[string]string) ?Response {
)
}
[params]
pub struct PostMultipartFormConfig {
pub mut:
form map[string]string
files map[string][]FileData
header Header
}
// post_multipart_form sends a POST HTTP request to the URL with multipart form data
pub fn post_multipart_form(url string, conf PostMultipartFormConfig) ?Response {
body, boundary := multipart_form_body(conf.form, conf.files)
mut header := conf.header
header.set(.content_type, 'multipart/form-data; boundary="$boundary"')
return fetch(
method: .post
url: url
header: new_header(key: .content_type, value: 'multipart/form-data; boundary="$boundary"')
header: header
data: body
)
}