From 1a214510da4e5330120ebc3fdadaa95d585762bb Mon Sep 17 00:00:00 2001 From: Carlana Date: Thu, 20 Aug 2026 09:48:12 -0400 Subject: [PATCH 1/4] Upgrade x/net --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0433859..090cb4a 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/carlmjohnson/requests go 1.25.0 -require golang.org/x/net v0.55.0 +require golang.org/x/net v0.58.0 diff --git a/go.sum b/go.sum index 9354ef5..0a44e17 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= -golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= +golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= +golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU= From c91b166619579e1138a41f708d16019465746269 Mon Sep 17 00:00:00 2001 From: Carlana Date: Thu, 20 Aug 2026 09:48:39 -0400 Subject: [PATCH 2/4] reqtest.Server: Fix for Go 1.27 in memory servers --- config.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index ba4ef61..d659344 100644 --- a/config.go +++ b/config.go @@ -40,9 +40,12 @@ func GzipConfig(level int, h func(gw *gzip.Writer) error) Config { // Deprecated: Use reqtest.Server. func TestServerConfig(s *httptest.Server) Config { return func(rb *Builder) { + // In memory servers don't set s.URL until after s.Client is called, + // so call that first. + cl := s.Client() rb. BaseURL(s.URL). - Client(s.Client()) + Client(cl) } } From 10f66a6193074a563c42b0aafb0e209ac2085ae3 Mon Sep 17 00:00:00 2001 From: Carlana Date: Thu, 20 Aug 2026 10:11:39 -0400 Subject: [PATCH 3/4] reqtest: Add ReplayFile --- reqtest/transport.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/reqtest/transport.go b/reqtest/transport.go index cfdefea..e1bc0c7 100644 --- a/reqtest/transport.go +++ b/reqtest/transport.go @@ -1,8 +1,11 @@ package reqtest import ( + "bufio" + "bytes" "io/fs" "net/http" + "os" "github.com/carlmjohnson/requests" ) @@ -29,6 +32,19 @@ func Replay(basepath string) requests.Transport { return requests.Replay(basepath) } +// ReplayFile returns an http.RoundTripper that reads its +// response from the response file at path. +func ReplayFile(path string) requests.Transport { + return requests.RoundTripFunc(func(req *http.Request) (res *http.Response, err error) { + b, err := os.ReadFile(path) + if err != nil { + return nil, err + } + r := bufio.NewReader(bytes.NewReader(b)) + return http.ReadResponse(r, req) + }) +} + // ReplayFS returns an http.RoundTripper that reads its // responses from text files in the fs.FS. // Responses are looked up according to a hash of the request. From 35ae746cb9ee7e372ab4e58e7be467c9118232d7 Mon Sep 17 00:00:00 2001 From: Carlana Date: Thu, 20 Aug 2026 10:11:57 -0400 Subject: [PATCH 4/4] ExampleGzipConfig: Use reqtest.ReplayFile --- config_example_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config_example_test.go b/config_example_test.go index f35c6dc..63d80e6 100644 --- a/config_example_test.go +++ b/config_example_test.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/carlmjohnson/requests" + "github.com/carlmjohnson/requests/reqtest" ) func ExampleNew() { @@ -52,6 +53,7 @@ func ExampleGzipConfig() { _, err := gw.Write([]byte(`hello, world`)) return err })). + Transport(reqtest.ReplayFile("testdata/postman-echo POST gzip pL_wuhOy.res.txt")). ToJSON(&echo). Fetch(context.Background()) if err != nil {