From 001ceab78458f3b96971c9c7831db198cefeda07 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Wed, 10 Jul 2024 01:56:29 +0530 Subject: [PATCH] add bare minimum DefaultTransport (#32) * add bare minimum DefaultTransport Signed-off-by: Rajat Jindal * use transport if explicitly configured by client Signed-off-by: Rajat Jindal --------- Signed-off-by: Rajat Jindal --- http/client.go | 4 ++++ http/transport.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/http/client.go b/http/client.go index 9a86604..09296f3 100644 --- a/http/client.go +++ b/http/client.go @@ -410,6 +410,10 @@ func urlErrorOp(method string) string { // Any returned error will be of type *url.Error. The url.Error // value's Timeout method will report true if the request timed out. func (c *Client) Do(req *Request) (*Response, error) { + if c.Transport != nil { + return c.Transport.RoundTrip(req) + } + return c.do(req) } diff --git a/http/transport.go b/http/transport.go index f117558..f39b748 100644 --- a/http/transport.go +++ b/http/transport.go @@ -20,3 +20,12 @@ type readTrackingBody struct { didRead bool didClose bool } + +type Transport struct{} + +var DefaultTransport RoundTripper = &Transport{} + +// roundTrip implements a RoundTripper over HTTP. +func (t *Transport) RoundTrip(req *Request) (*Response, error) { + return roundTrip(req) +}