Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: buildCurlRequest() replace req.Body with req.GetBody() #844

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion util_curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ func buildCurlRequest(req *http.Request, httpCookiejar http.CookieJar) (curl str

// 3. Generate curl body
if req.Body != nil {
buf, _ := io.ReadAll(req.Body)
// httpclient.Do method will read the entire body and make it empty
// thus using req.GetBody() instead of req.Body since req.Body
// is empty after Do method.
// body here is a copy of original body
body, _ := req.GetBody()
buf, _ := io.ReadAll(body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tttturtle-russ Thanks for creating a PR. Last night, I discovered the branch main was missing curl middleware. It seems it happened when I merged the branch v2 into branch main.

Branch main

resty/resty.go

Lines 195 to 196 in 6d941ac

addCredentials,
}

Branch v2

resty/client.go

Lines 1484 to 1486 in 370d744

addCredentials,
createCurlCmd,
}

req.Body = io.NopCloser(bytes.NewBuffer(buf)) // important!!
curl += `-d ` + shellescape.Quote(string(buf))
}
Expand Down