2021-02-02 12:05:47 +01:00
|
|
|
// Package oldhttptransport contains HTTP transport extensions. Here we
|
|
|
|
// define a http.Transport that emits events.
|
|
|
|
package oldhttptransport
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Transport performs single HTTP transactions and emits
|
|
|
|
// measurement events as they happen.
|
|
|
|
type Transport struct {
|
|
|
|
roundTripper http.RoundTripper
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates a new Transport.
|
|
|
|
func New(roundTripper http.RoundTripper) *Transport {
|
|
|
|
return &Transport{
|
2021-06-23 13:36:45 +02:00
|
|
|
roundTripper: NewBodyTracer(NewTraceTripper(roundTripper)),
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RoundTrip executes a single HTTP transaction, returning
|
|
|
|
// a Response for the provided Request.
|
|
|
|
func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
|
|
|
|
return t.roundTripper.RoundTrip(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CloseIdleConnections closes the idle connections.
|
|
|
|
func (t *Transport) CloseIdleConnections() {
|
|
|
|
// Adapted from net/http code
|
|
|
|
type closeIdler interface {
|
|
|
|
CloseIdleConnections()
|
|
|
|
}
|
|
|
|
if tr, ok := t.roundTripper.(closeIdler); ok {
|
|
|
|
tr.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
}
|