Merge pull request #2985 from novas0x2a/default-transport

make it possible to wrap the client transport in another one
This commit is contained in:
Derek McGowan 2019-12-13 11:36:12 -08:00 committed by GitHub
commit bdf3438b52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -6,6 +6,13 @@ import (
"sync"
)
func identityTransportWrapper(rt http.RoundTripper) http.RoundTripper {
return rt
}
// DefaultTransportWrapper allows a user to wrap every generated transport
var DefaultTransportWrapper = identityTransportWrapper
// RequestModifier represents an object which will do an inplace
// modification of an HTTP request.
type RequestModifier interface {
@ -31,10 +38,11 @@ func (h headerModifier) ModifyRequest(req *http.Request) error {
// NewTransport creates a new transport which will apply modifiers to
// the request on a RoundTrip call.
func NewTransport(base http.RoundTripper, modifiers ...RequestModifier) http.RoundTripper {
return &transport{
Modifiers: modifiers,
Base: base,
}
return DefaultTransportWrapper(
&transport{
Modifiers: modifiers,
Base: base,
})
}
// transport is an http.RoundTripper that makes HTTP requests after