cleanup(netx): remove unused proxy-via-context codepath (#367)

We always set the proxy explicitly now. So, let us remove this
extra bit of code we're not using.

Part of https://github.com/ooni/probe/issues/1507.
This commit is contained in:
Simone Basso
2021-06-08 22:26:24 +02:00
committed by GitHub
parent 8ad17775fa
commit b8cae3f5a6
5 changed files with 1 additions and 73 deletions
-11
View File
@@ -10,8 +10,6 @@ import (
"io/ioutil"
"net/http"
"net/url"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
)
// Logger is the definition of Logger used by this package.
@@ -40,10 +38,6 @@ type Client struct {
// Logger is the logger to use.
Logger Logger
// ProxyURL allows to force a proxy URL to fallback to a
// tunnel, e.g., Psiphon.
ProxyURL *url.URL
// UserAgent is the user agent to use.
UserAgent string
}
@@ -93,11 +87,6 @@ func (c Client) NewRequest(ctx context.Context, method, resourcePath string,
request.Header.Set("Accept", c.Accept)
}
request.Header.Set("User-Agent", c.UserAgent)
// Implementation note: the following allows tunneling if c.ProxyURL
// is not nil. Because the proxy URL is set as part of each request
// generated using this function, every request that eventually needs
// to reconnect will always do so using the proxy.
ctx = dialer.WithProxyURL(ctx, c.ProxyURL)
return request.WithContext(ctx), nil
}
-21
View File
@@ -10,9 +10,7 @@ import (
"testing"
"github.com/apex/log"
"github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
)
const userAgent = "miniooni/0.1.0-dev"
@@ -153,21 +151,6 @@ func TestNewRequestUserAgentIsSet(t *testing.T) {
}
}
func TestNewRequestTunnelingIsPossible(t *testing.T) {
client := newClient()
client.ProxyURL = &url.URL{Scheme: "socks5", Host: "[::1]:54321"}
req, err := client.NewRequest(
context.Background(), "GET", "/", nil, nil,
)
if err != nil {
t.Fatal(err)
}
cmp := cmp.Diff(dialer.ContextProxyURL(req.Context()), client.ProxyURL)
if cmp != "" {
t.Fatal(cmp)
}
}
func TestClientDoJSONClientDoFailure(t *testing.T) {
expected := errors.New("mocked error")
client := newClient()
@@ -265,10 +248,6 @@ func TestCreateJSONSuccess(t *testing.T) {
}
}
type httpbinput struct {
Data string `json:"data"`
}
func TestUpdateJSONSuccess(t *testing.T) {
headers := httpbinheaders{
Headers: map[string]string{