feat(httpx): implement optional body logging also on http error (#651)
1. we want optionally to log the body (we don't want to log the body when we're fetching psiphon secrets or tor targets) 2. we want body logging to _also_ happen on error since this is quite useful to debug possible errors when accessing the API This diff adds the above functionality, which were previously described in https://github.com/ooni/probe/issues/1951. This diff also adds comprehensive testing.
This commit is contained in:
@@ -24,7 +24,7 @@ func avastIPLookup(
|
||||
HTTPClient: httpClient,
|
||||
Logger: logger,
|
||||
UserAgent: userAgent,
|
||||
}).Build().GetJSON(ctx, "/v1/info", &v)
|
||||
}).WithBodyLogging().Build().GetJSON(ctx, "/v1/info", &v)
|
||||
if err != nil {
|
||||
return DefaultProbeIP, err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func ipConfigIPLookup(
|
||||
HTTPClient: httpClient,
|
||||
Logger: logger,
|
||||
UserAgent: httpheader.CLIUserAgent(),
|
||||
}).Build().FetchResource(ctx, "/")
|
||||
}).WithBodyLogging().Build().FetchResource(ctx, "/")
|
||||
if err != nil {
|
||||
return DefaultProbeIP, err
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func ipInfoIPLookup(
|
||||
HTTPClient: httpClient,
|
||||
Logger: logger,
|
||||
UserAgent: httpheader.CLIUserAgent(), // we must be a CLI client
|
||||
}).Build().GetJSON(ctx, "/", &v)
|
||||
}).WithBodyLogging().Build().GetJSON(ctx, "/", &v)
|
||||
if err != nil {
|
||||
return DefaultProbeIP, err
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func ubuntuIPLookup(
|
||||
HTTPClient: httpClient,
|
||||
Logger: logger,
|
||||
UserAgent: userAgent,
|
||||
}).Build().FetchResource(ctx, "/lookup")
|
||||
}).WithBodyLogging().Build().FetchResource(ctx, "/lookup")
|
||||
if err != nil {
|
||||
return DefaultProbeIP, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user