-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup(netxlite): add file for quirky behavior required by netx
There are a bunch of quirks in the codebase that are there because the ./legacy/netx package assumes them. So, in light of the fact that I'm going to modify how we construct HTTP clients, I feel a bit safer if we move what I should not touch in a different place. Part of ooni/probe#2531
- Loading branch information
1 parent
873b4e1
commit f71b4a3
Showing
4 changed files
with
44 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package netxlite | ||
|
||
// | ||
// Wrappers for already constructed types. | ||
// | ||
|
||
import ( | ||
"github.com/ooni/probe-cli/v3/internal/model" | ||
) | ||
|
||
// WrapHTTPTransport creates an HTTPTransport using the given logger | ||
// and guarantees that returned errors are wrapped. | ||
// | ||
// This is a low level factory. Consider not using it directly. | ||
func WrapHTTPTransport(logger model.DebugLogger, txp model.HTTPTransport) model.HTTPTransport { | ||
return &httpTransportLogger{ | ||
HTTPTransport: &httpTransportErrWrapper{txp}, | ||
Logger: logger, | ||
} | ||
} | ||
|
||
// WrapHTTPClient wraps an HTTP client to add error wrapping capabilities. | ||
// | ||
// This is a low level factory. Consider not using it directly. | ||
func WrapHTTPClient(clnt model.HTTPClient) model.HTTPClient { | ||
return &httpClientErrWrapper{clnt} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package netxlite | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestWrapHTTPClient(t *testing.T) { | ||
origClient := &http.Client{} | ||
wrapped := WrapHTTPClient(origClient) | ||
errWrapper := wrapped.(*httpClientErrWrapper) | ||
innerClient := errWrapper.HTTPClient.(*http.Client) | ||
if innerClient != origClient { | ||
t.Fatal("not the inner client we expected") | ||
} | ||
} |