diff --git a/internal/enginelocate/cloudflare.go b/internal/enginelocate/cloudflare.go index ff97b90ab..04b22d10d 100644 --- a/internal/enginelocate/cloudflare.go +++ b/internal/enginelocate/cloudflare.go @@ -6,7 +6,7 @@ import ( "regexp" "strings" - "github.com/ooni/probe-cli/v3/internal/httpx" + "github.com/ooni/probe-cli/v3/internal/httpclientx" "github.com/ooni/probe-cli/v3/internal/model" ) @@ -18,12 +18,12 @@ func cloudflareIPLookup( resolver model.Resolver, ) (string, error) { // get the raw response body - data, err := (&httpx.APIClientTemplate{ - BaseURL: "https://www.cloudflare.com", - HTTPClient: httpClient, - Logger: logger, - UserAgent: model.HTTPHeaderUserAgent, - }).WithBodyLogging().Build().FetchResource(ctx, "/cdn-cgi/trace") + data, err := httpclientx.GetRaw(ctx, "https://www.cloudflare.com/cdn-cgi/trace", &httpclientx.Config{ + Authorization: "", // not needed + Client: httpClient, + Logger: logger, + UserAgent: userAgent, + }) // handle the error case if err != nil { @@ -33,7 +33,6 @@ func cloudflareIPLookup( // find the IP addr r := regexp.MustCompile("(?:ip)=(.*)") ip := strings.Trim(string(r.Find(data)), "ip=") - logger.Debugf("cloudflare: body: %s", ip) // make sure the IP addr is valid if net.ParseIP(ip) == nil { diff --git a/internal/enginelocate/ubuntu.go b/internal/enginelocate/ubuntu.go index 77d9b5cbc..c005ee1a7 100644 --- a/internal/enginelocate/ubuntu.go +++ b/internal/enginelocate/ubuntu.go @@ -5,7 +5,7 @@ import ( "encoding/xml" "net" - "github.com/ooni/probe-cli/v3/internal/httpx" + "github.com/ooni/probe-cli/v3/internal/httpclientx" "github.com/ooni/probe-cli/v3/internal/model" ) @@ -21,23 +21,13 @@ func ubuntuIPLookup( userAgent string, resolver model.Resolver, ) (string, error) { - // read the HTTP response body - data, err := (&httpx.APIClientTemplate{ - BaseURL: "https://geoip.ubuntu.com/", - HTTPClient: httpClient, - Logger: logger, - UserAgent: userAgent, - }).WithBodyLogging().Build().FetchResource(ctx, "/lookup") - - // handle the error case - if err != nil { - return model.DefaultProbeIP, err - } - - // parse the XML - logger.Debugf("ubuntu: body: %s", string(data)) - var v ubuntuResponse - err = xml.Unmarshal(data, &v) + // read the HTTP response and parse as XML + v, err := httpclientx.GetXML[*ubuntuResponse](ctx, "https://geoip.ubuntu.com/lookup", &httpclientx.Config{ + Authorization: "", // not needed + Client: httpClient, + Logger: logger, + UserAgent: userAgent, + }) // handle the error case if err != nil {