diff options
author | tjp <tjp@ctrl-c.club> | 2024-01-10 11:06:53 -0700 |
---|---|---|
committer | tjp <tjp@ctrl-c.club> | 2024-01-10 11:10:09 -0700 |
commit | b6c0ba24cf5902e6bafff4243979bb12010aa142 (patch) | |
tree | 39034f7f4a41ff08393445f33769d262e4644c8f | |
parent | b09d2de941b65956eb7c748e3ce44ff568d4c2af (diff) |
add a *Request to Response
-rw-r--r-- | finger/client.go | 2 | ||||
-rw-r--r-- | gemini/client.go | 3 | ||||
-rw-r--r-- | gopher/client.go | 2 | ||||
-rw-r--r-- | internal/types/response.go | 6 | ||||
-rw-r--r-- | nex/client.go | 2 | ||||
-rw-r--r-- | spartan/client.go | 1 |
6 files changed, 12 insertions, 4 deletions
diff --git a/finger/client.go b/finger/client.go index bd1e3bf..0488b79 100644 --- a/finger/client.go +++ b/finger/client.go @@ -51,7 +51,7 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) { return nil, err } - return &types.Response{Body: bytes.NewBuffer(response)}, nil + return &types.Response{Body: bytes.NewBuffer(response), Request: request}, nil } // Fetch resolves a finger query. diff --git a/gemini/client.go b/gemini/client.go index c60e92e..00e28f6 100644 --- a/gemini/client.go +++ b/gemini/client.go @@ -29,7 +29,7 @@ type Client struct { // NewClient creates a gemini Client with the given TLS configuration and default MaxRedirects. func NewClient(tlsConf *tls.Config) Client { - if tlsConf != nil { + if tlsConf != nil && !tlsConf.InsecureSkipVerify { tlsConf = tlsConf.Clone() tlsConf.InsecureSkipVerify = true } @@ -116,6 +116,7 @@ func (client Client) RoundTrip(request *types.Request) (*types.Response, error) return nil, err } response.Body = bytes.NewBuffer(bodybuf) + response.Request = request return response, nil } diff --git a/gopher/client.go b/gopher/client.go index a5c4228..0ae1730 100644 --- a/gopher/client.go +++ b/gopher/client.go @@ -52,7 +52,7 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) { return nil, err } - return &types.Response{Body: bytes.NewBuffer(response)}, nil + return &types.Response{Body: bytes.NewBuffer(response), Request: request}, nil } // Fetch parses a URL string and fetches the gopher resource. diff --git a/internal/types/response.go b/internal/types/response.go index 26dda05..ccd23b6 100644 --- a/internal/types/response.go +++ b/internal/types/response.go @@ -18,6 +18,12 @@ type Response struct { // Body is the response body, if any. Body io.Reader + + // Request is the request which generated this response. + // + // Available in clients. + // Not set in servers, and there is no need to set it in server handlers. + Request *Request } func (response *Response) Close() error { diff --git a/nex/client.go b/nex/client.go index 5f53746..4a34903 100644 --- a/nex/client.go +++ b/nex/client.go @@ -46,7 +46,7 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) { return nil, err } - return &types.Response{Body: bytes.NewBuffer(response)}, nil + return &types.Response{Body: bytes.NewBuffer(response), Request: request}, nil } // Fetch builds and sends a nex request, and returns the response. diff --git a/spartan/client.go b/spartan/client.go index affcf95..81f2132 100644 --- a/spartan/client.go +++ b/spartan/client.go @@ -82,6 +82,7 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) { return nil, err } response.Body = bytes.NewBuffer(bodybuf) + response.Request = request return response, nil } |