deb1589bdb
I have recently seen a data race related our way of mutating the outgoing request to set the host header. Unfortunately, I've lost track of the race output, because I rebooted my Linux box before saving it. Though, after inspecting why and and where we're mutating outgoing requets, I've found that: 1. we add the host header when logging to have it logged, which is not a big deal since we already emit the URL rather than just the URL path when logging a request, and so we can safely zap this piece of code; 2. as a result, in measurements we may omit the host header but again this is pretty much obvious from the URL itself and so it should not be very important (nonetheless, avoid surprises and keep the existing behavior); 3. when the User-Agent header is not set, we default to a `miniooni/0.1.0-dev` user agent, which is probably not very useful anyway, so we can actually remove it. Part of https://github.com/ooni/probe/issues/1733 (this diff has been extracted from https://github.com/ooni/probe-cli/pull/506).
38 lines
987 B
Go
38 lines
987 B
Go
// 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{
|
|
roundTripper: NewBodyTracer(NewTraceTripper(roundTripper)),
|
|
}
|
|
}
|
|
|
|
// 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()
|
|
}
|
|
}
|