refactor(httpx): improve and modernize (1/n) (#647)
This PR starts to implement the refactoring described at https://github.com/ooni/probe/issues/1951. I originally wrote more patches than the ones in this PR, but overall they were not readable. Since I want to squash and merge, here's a reasonable subset of the original patches that will still be readable and understandable in the future.
This commit is contained in:
parent
0a630c1716
commit
7b7df2c6af
25 changed files with 173 additions and 294 deletions
|
|
@ -65,7 +65,7 @@ type Session interface {
|
|||
|
||||
// Client is a client for the OONI probe services API.
|
||||
type Client struct {
|
||||
httpx.Client
|
||||
httpx.APIClient
|
||||
LoginCalls *atomicx.Int64
|
||||
RegisterCalls *atomicx.Int64
|
||||
StateFile StateFile
|
||||
|
|
@ -91,7 +91,7 @@ func (c Client) GetCredsAndAuth() (*LoginCredentials, *LoginAuth, error) {
|
|||
// function fails, e.g., we don't support the specified endpoint.
|
||||
func NewClient(sess Session, endpoint model.OOAPIService) (*Client, error) {
|
||||
client := &Client{
|
||||
Client: httpx.Client{
|
||||
APIClient: httpx.APIClient{
|
||||
BaseURL: endpoint.Address,
|
||||
HTTPClient: sess.DefaultHTTPClient(),
|
||||
Logger: sess.Logger(),
|
||||
|
|
@ -115,7 +115,7 @@ func NewClient(sess Session, endpoint model.OOAPIService) (*Client, error) {
|
|||
if URL.Scheme != "https" || URL.Host != URL.Hostname() {
|
||||
return nil, ErrUnsupportedCloudFrontAddress
|
||||
}
|
||||
client.Client.Host = URL.Hostname()
|
||||
client.APIClient.Host = URL.Hostname()
|
||||
URL.Host = endpoint.Front
|
||||
client.BaseURL = URL.String()
|
||||
if _, err := url.Parse(client.BaseURL); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue