diff --git a/stdlibwrapper.go b/stdlibwrapper.go new file mode 100644 index 00000000..9e12d0b8 --- /dev/null +++ b/stdlibwrapper.go @@ -0,0 +1,39 @@ +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 { + 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, + TLS: resp.TLS, + } + return stdResp, nil +}