Repository navigation
feat(enhancement): Use http.Cookie to compose values in generated curl commands - #1250
Conversation
Assisted-by: OpenAI GPT-6 <noreply@openai.com>
|
@Aurantium-47 I need time to analyze and get back. If you have any handy example to demonstrate the issue, kindly share. |
|
Here is a runnable example using only Resty and a loopback HTTP server: package main
import (
"fmt"
"io"
"net/http"
"net/http/cookiejar"
"net/http/httptest"
"net/url"
"resty.dev/v3"
)
func main() {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = io.WriteString(w, r.Header.Get("Cookie"))
}))
defer server.Close()
u, _ := url.Parse(server.URL)
jar, _ := cookiejar.New(nil)
jar.SetCookies(u, []*http.Cookie{{Name: "session", Value: "YWJj+/=="}})
client := resty.New().SetCookieJar(jar)
defer client.Close()
request := client.R().SetMethod(http.MethodGet).SetURL(server.URL).SetCurlCmdGenerate(true)
fmt.Println("Generated command:", request.CurlCmd())
response, err := request.Get(server.URL)
if err != nil {
panic(err)
}
fmt.Println("Cookie received by server:", response.String())
}On the original PR base ( OpenAI Codex ran this on Windows with Go 1.27.2 against the PR checkout, then with a Go overlay replacing only Prepared and tested with OpenAI Codex assistance. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v3 #1250 +/- ##
==========================================
- Coverage 99.75% 99.75% -0.01%
==========================================
Files 20 20
Lines 3631 3628 -3
==========================================
- Hits 3622 3619 -3
Misses 9 9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Cookie-jar values are URL-query-escaped when generating curl commands. For example, a request sends
session=YWJj+/==, but its generated command sendssession=YWJj%2B%2F%3D%3D. Percent signs and quoted values are also changed, so copying the command cannot reproduce the original request.Build the cookie header with
http.Request.AddCookie, matching the serialization used by the HTTP client. Regression tests compare generated commands with headers received by a loopback server for base64, percent signs, spaces, commas, explicitly quoted values, and plain/empty controls.Validated on Go 1.27.2 / Windows: all curl tests,
go vet,go build, formatting, 100% coverage of the changed helper, and 18 real curl replays. The full shuffled suite has one unrelated failure in the existing invalid-request trace timing assertion, also reproduced on the unchanged base. Race tests were not run locally.Prepared and tested with OpenAI Codex assistance.