go-resty / resty

Simple HTTP and REST client library for Go
MIT License
10.01k stars 706 forks source link

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

Closed tttturtle-russ closed 1 month ago

tttturtle-russ commented 1 month ago

The `TestGenerateExecutedCurl` failure started after I merged from branch `v2` to branch `main`. It needs to investigate why it's failing.

Originally posted by @jeevatkm in https://github.com/go-resty/resty/issues/827#issuecomment-2323726014

Hi jeevatkm, I've found the reason why the test case failed. In https://github.com/go-resty/resty/blob/6d941ac6f1ed35557b6fb3fb41cf74beeb9be2f0/client.go#L1601 Do method will read the req.RawRequest.Body and make it empty. When generating curl body it will read an empty string, and that's why it failed.

This commit offers a temporary solution to this problem, I think the ultimate solution is to add a Clone method in Request, as #718 describes.

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.67%. Comparing base (82ae758) to head (24ae356). Report is 13 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #844 +/- ## ========================================== - Coverage 96.89% 96.67% -0.22% ========================================== Files 14 13 -1 Lines 1773 2048 +275 ========================================== + Hits 1718 1980 +262 - Misses 35 46 +11 - Partials 20 22 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tttturtle-russ commented 1 month ago

@jeevatkm OK, I will close this PR and create a new one with curl middleware added.