From 892d5f3a4262f90e041eaa8805b34355397bb4ec Mon Sep 17 00:00:00 2001 From: Luis Gerhorst Date: Wed, 26 Jul 2023 15:41:23 +0000 Subject: [PATCH] Keep body if request uses chunked TransferEncoding Fixes https://github.com/awslabs/aws-sigv4-proxy/issues/151 --- handler/proxy_client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/handler/proxy_client.go b/handler/proxy_client.go index e5682e2..15028f4 100644 --- a/handler/proxy_client.go +++ b/handler/proxy_client.go @@ -149,7 +149,11 @@ func (p *ProxyClient) Do(req *http.Request) (*http.Response, error) { // to magically set Transfer-Encoding: chunked. Service like S3 does not support chunk encoding. // We need to manipulate the Body value after signv4 signing because the signing process wraps // the original body into another struct, which will result in Transfer-Encoding: chunked being set. - if proxyReq.ContentLength == 0 { + // + // If the original request has the outermost "chunked" TransferEncoding, do + // not remove the body as the ContentLength header will then be missing + // (which Go reports as a length of 0). + if proxyReq.ContentLength == 0 && !(len(req.TransferEncoding) >= 1 && req.TransferEncoding[0] == "chunked") { proxyReq.Body = http.NoBody }