From 22545e0a3878e08ba45474819156dac8412a0e44 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Fri, 8 Nov 2024 12:00:56 +0100 Subject: [PATCH] Restore request body after reading in `sign` method Fixes #225 The problem is the the `sign` method in ProxyClient reads the `req.Body` and that results in a closed reader. When the request is actually send to the transport later, the body cannot be read and results in a body length of 0 which does not match the passed req.ContentLength. We tried to write tests for this, but the tests are not fully matching the real world because: * they use io.NopCloser * they use a HTTP mock client that doesn't actually read the body to send to the proxy (makes sense, its a mock, but it's different than the actual implementation) --- handler/proxy_client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/handler/proxy_client.go b/handler/proxy_client.go index e591260..dff5900 100644 --- a/handler/proxy_client.go +++ b/handler/proxy_client.go @@ -59,6 +59,7 @@ func (p *ProxyClient) sign(req *http.Request, service *endpoints.ResolvedEndpoin } body = bytes.NewReader(b) + req.Body = io.NopCloser(bytes.NewReader(b)) } // S3 service should not have any escaping applied.