From 0de6d1edc4c902044744cdf832113f9aeb167fc5 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 9 Nov 2021 12:10:40 +0100 Subject: fix(fetch): set content-length for empty POST/PUT (#12703) This commit changes `fetch` to set `content-length: 0` on POST and PUT requests with no body. --- ext/fetch/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ext/fetch') diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index b4bffb6de..4bd62cd7c 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -246,7 +246,7 @@ where let permissions = state.borrow_mut::(); permissions.check_net_url(&url)?; - let mut request = client.request(method, url); + let mut request = client.request(method.clone(), url); let request_body_rid = if args.has_body { match data { @@ -278,6 +278,11 @@ where } } } else { + // POST and PUT requests should always have a 0 length content-length, + // if there is no body. https://fetch.spec.whatwg.org/#http-network-or-cache-fetch + if matches!(method, Method::POST | Method::PUT) { + request = request.header(CONTENT_LENGTH, HeaderValue::from(0)); + } None }; -- cgit v1.2.3