Fix redirect behavior for 307/308 status codes
Closed this issue · 1 comments
The way RunWithContext
is set up inside httpc
, it prevents some important features which are available via NewRequestWithContext
from net/http
:
If body is of type *bytes.Buffer, *bytes.Reader, or *strings.Reader, the returned request's ContentLength is set to its exact value
(instead of -1), GetBody is populated (so 307 and 308 redirects can replay the body), and Body is set to NoBody if the
ContentLength
is 0.
This popped up testing github.com/els0r/goProbe trying to call global-query
with goQuery
, failing because the ingress in front of the global-query server redirected /_query
to /_query/
. httpc
, or more specifically net/http
wasn't following the request since the body isn't supplied to NewRequestWithContext
.