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:
@@ -9,6 +9,6 @@ import (
|
||||
// GetTestHelpers is like GetCollectors but for test helpers.
|
||||
func (c Client) GetTestHelpers(
|
||||
ctx context.Context) (output map[string][]model.OOAPIService, err error) {
|
||||
err = c.APIClientTemplate.Build().GetJSON(ctx, "/api/v1/test-helpers", &output)
|
||||
err = c.APIClientTemplate.WithBodyLogging().Build().GetJSON(ctx, "/api/v1/test-helpers", &output)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func (c Client) CheckReportID(ctx context.Context, reportID string) (bool, error
|
||||
HTTPClient: c.HTTPClient,
|
||||
Logger: c.Logger,
|
||||
UserAgent: c.UserAgent,
|
||||
}).Build().GetJSONWithQuery(ctx, "/api/_/check_report_id", query, &response)
|
||||
}).WithBodyLogging().Build().GetJSONWithQuery(ctx, "/api/_/check_report_id", query, &response)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (c Client) OpenReport(ctx context.Context, rt ReportTemplate) (ReportChanne
|
||||
return nil, ErrUnsupportedFormat
|
||||
}
|
||||
var cor collectorOpenResponse
|
||||
if err := c.APIClientTemplate.Build().PostJSON(ctx, "/report", rt, &cor); err != nil {
|
||||
if err := c.APIClientTemplate.WithBodyLogging().Build().PostJSON(ctx, "/report", rt, &cor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, format := range cor.SupportedFormats {
|
||||
@@ -144,7 +144,7 @@ func (r reportChan) CanSubmit(m *model.Measurement) bool {
|
||||
func (r reportChan) SubmitMeasurement(ctx context.Context, m *model.Measurement) error {
|
||||
var updateResponse collectorUpdateResponse
|
||||
m.ReportID = r.ID
|
||||
err := r.client.APIClientTemplate.Build().PostJSON(
|
||||
err := r.client.APIClientTemplate.WithBodyLogging().Build().PostJSON(
|
||||
ctx, fmt.Sprintf("/report/%s", r.ID), collectorUpdateRequest{
|
||||
Format: "json",
|
||||
Content: m,
|
||||
|
||||
@@ -59,7 +59,7 @@ func (c Client) GetMeasurementMeta(
|
||||
HTTPClient: c.HTTPClient,
|
||||
Logger: c.Logger,
|
||||
UserAgent: c.UserAgent,
|
||||
}).Build().GetJSONWithQuery(ctx, "/api/v1/measurement_meta", query, &response)
|
||||
}).WithBodyLogging().Build().GetJSONWithQuery(ctx, "/api/v1/measurement_meta", query, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (c Client) FetchURLList(ctx context.Context, config model.OOAPIURLListConfi
|
||||
query.Set("category_codes", strings.Join(config.Categories, ","))
|
||||
}
|
||||
var response urlListResult
|
||||
err := c.APIClientTemplate.Build().GetJSONWithQuery(ctx,
|
||||
err := c.APIClientTemplate.WithBodyLogging().Build().GetJSONWithQuery(ctx,
|
||||
"/api/v1/test-list/urls", query, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user