From 956fdffd96136948cca8fd8d2271aceb6aa6734d Mon Sep 17 00:00:00 2001 From: Miccah Date: Sat, 25 Sep 2021 02:09:49 -0500 Subject: [PATCH] net.http: allow custom headers in post_multipart_form (#11971) --- vlib/net/http/http.v | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vlib/net/http/http.v b/vlib/net/http/http.v index 7f7f867e81..a830d578d0 100644 --- a/vlib/net/http/http.v +++ b/vlib/net/http/http.v @@ -80,18 +80,23 @@ pub fn post_form(url string, data map[string]string) ?Response { ) } +[params] pub struct PostMultipartFormConfig { - form map[string]string - files map[string][]FileData +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 ) }