Skip to content

Conversation

@dwisiswant0
Copy link
Member

@dwisiswant0 dwisiswant0 commented Dec 5, 2025

Description

When sending POST requests with a non-empty body
that trigger 307/308 redirects, the redirects fail
because the underlying http.Request.GetBody is
nil by default.

This patch populates GetBody using the existing
reusable body reader, allowing the net/http
client to rewind and replay the body.

Fixes #493.

Proof

patch:

$ go test -v -race -run "^TestRedirectPOST" .
=== RUN   TestRedirectPOSTWithBody
--- PASS: TestRedirectPOSTWithBody (0.00s)
=== RUN   TestRedirectPOSTWithBodyFromRequest
--- PASS: TestRedirectPOSTWithBodyFromRequest (0.00s)
PASS
ok  	github.com/projectdiscovery/retryablehttp-go	1.052s

main:

$ git cherry-pick e49953b
[main 9b73fba] test: adds `TestRedirectPOST*` tests
 Date: Sat Dec 6 00:04:02 2025 +0700
 1 file changed, 124 insertions(+)
$ go test -v -race -run "^TestRedirectPOST" .
=== RUN   TestRedirectPOSTWithBody
    request_test.go:105: Expected status 200, got 307. Body: 
--- FAIL: TestRedirectPOSTWithBody (0.00s)
=== RUN   TestRedirectPOSTWithBodyFromRequest
--- PASS: TestRedirectPOSTWithBodyFromRequest (0.00s)
FAIL
FAIL	github.com/projectdiscovery/retryablehttp-go	0.052s
FAIL

When sending POST requests with a non-empty body
that trigger 307/308 redirects, the redirects fail
because the underlying `http.Request.GetBody` is
nil by default.

This patch populates `GetBody` using the existing
reusable body reader, allowing the `net/http`
client to rewind and replay the body.

Fixes #493.

Signed-off-by: Dwi Siswanto <[email protected]>
@dwisiswant0 dwisiswant0 requested a review from Mzack9999 December 5, 2025 17:07
Signed-off-by: Dwi Siswanto <[email protected]>
@dwisiswant0 dwisiswant0 marked this pull request as draft December 6, 2025 05:18
@dwisiswant0
Copy link
Member Author

Superseded by #496

@dwisiswant0 dwisiswant0 closed this Dec 6, 2025
@dwisiswant0 dwisiswant0 deleted the dwisiswant0/fix/populate-GetBody-to-support-307-308-redirects branch December 6, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

307/308 Redirects Fail for POST Requests with Non-Empty Body (Missing req.GetBody)

2 participants