From abcddca6a1cc21efcf865917c2f6f394ed6e4322 Mon Sep 17 00:00:00 2001 From: kelmenhorst Date: Tue, 17 Aug 2021 18:32:34 +0200 Subject: [PATCH 1/3] added StdlibTransport --- stdlibwrapper.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 stdlibwrapper.go diff --git a/stdlibwrapper.go b/stdlibwrapper.go new file mode 100644 index 00000000..355b3378 --- /dev/null +++ b/stdlibwrapper.go @@ -0,0 +1,38 @@ +// This is an adapter for integrating net/http dependend code. + +package http + +import "net/http" + +type StdlibTransport struct { + Transport +} + +func (txp *StdlibTransport) RoundTrip(stdReq *http.Request) (*http.Response, error) { + req, err := NewRequest(stdReq.Method, stdReq.URL.String(), stdReq.Body) + if err != nil { + return nil, err + } + req.Header = Header(stdReq.Header) + resp, err := txp.Transport.RoundTrip(req) + if err != nil { + return nil, err + } + stdResp := &http.Response{ + Status: resp.Status, + StatusCode: resp.StatusCode, + Proto: resp.Proto, + ProtoMinor: resp.ProtoMinor, + ProtoMajor: resp.ProtoMajor, + Header: http.Header(resp.Header), + Body: resp.Body, + ContentLength: resp.ContentLength, + TransferEncoding: resp.TransferEncoding, + Close: resp.Close, + Uncompressed: resp.Uncompressed, + Trailer: http.Header(resp.Trailer), + Request: stdReq, // TODO(kelmenhorst,bassosimone): is this ok? + TLS: resp.TLS, + } + return stdResp, nil +} From d70f3cc93e5da22be85a6ea4487d09b38672fae3 Mon Sep 17 00:00:00 2001 From: kelmenhorst Date: Tue, 17 Aug 2021 20:59:09 +0200 Subject: [PATCH 2/3] updated comments --- stdlibwrapper.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlibwrapper.go b/stdlibwrapper.go index 355b3378..021e8b06 100644 --- a/stdlibwrapper.go +++ b/stdlibwrapper.go @@ -1,13 +1,14 @@ -// This is an adapter for integrating net/http dependend code. - package http import "net/http" +// StdlibTransport is an adapter for integrating net/http dependend code. +// It looks like an http.RoundTripper but uses this fork internally. type StdlibTransport struct { Transport } +// RoundTrip implements the http.RoundTripper interface. func (txp *StdlibTransport) RoundTrip(stdReq *http.Request) (*http.Response, error) { req, err := NewRequest(stdReq.Method, stdReq.URL.String(), stdReq.Body) if err != nil { From 6ef7f51f1cd185659889d59ba471ea76d48474eb Mon Sep 17 00:00:00 2001 From: kelmenhorst Date: Tue, 17 Aug 2021 22:00:06 +0200 Subject: [PATCH 3/3] removed todo comment --- stdlibwrapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlibwrapper.go b/stdlibwrapper.go index 021e8b06..9e12d0b8 100644 --- a/stdlibwrapper.go +++ b/stdlibwrapper.go @@ -32,7 +32,7 @@ func (txp *StdlibTransport) RoundTrip(stdReq *http.Request) (*http.Response, err Close: resp.Close, Uncompressed: resp.Uncompressed, Trailer: http.Header(resp.Trailer), - Request: stdReq, // TODO(kelmenhorst,bassosimone): is this ok? + Request: stdReq, TLS: resp.TLS, } return stdResp, nil