From b079166b6c28145ed4118f76fc49a3fd7fd012bc Mon Sep 17 00:00:00 2001 From: Marcos Date: Fri, 23 Sep 2022 00:52:51 +0200 Subject: [PATCH] fix: prevent chunked requests As prior to this commit, 'content-length' header was not being properly set, golang net/http client interpreted those requests to be chunked, as streaming requests can't have content length set beforehand. --- adapter_fasthttp.go | 1 + adapter_native.go | 1 + 2 files changed, 2 insertions(+) diff --git a/adapter_fasthttp.go b/adapter_fasthttp.go index 91dd73f..2561808 100644 --- a/adapter_fasthttp.go +++ b/adapter_fasthttp.go @@ -78,6 +78,7 @@ func (a *fastHttpReqAdapter) SetBodyStream(body io.ReadWriteCloser, bodySize int func (a *fastHttpReqAdapter) SetBody(body []byte) { a.req.SetBody(body) + a.req.Header.SetContentLength(len(body)) } func (a *fastHttpReqAdapter) Body() (bts []byte) { diff --git a/adapter_native.go b/adapter_native.go index 1ad066d..fff3342 100644 --- a/adapter_native.go +++ b/adapter_native.go @@ -54,6 +54,7 @@ func (a *nativeReqAdapter) SetBody(payload []byte) { // TODO: pool these readers a.body = closableReaderWriter{ReadWriter: bytes.NewBuffer(payload)} a.req.Body = a.body + a.req.ContentLength = int64(len(payload)) } func (a *nativeReqAdapter) Body() []byte {