Skip to content

requestheaders: new parameter inside debug.httpcalls.<BIDDER> to log request header details #1659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,19 @@ func getAssetByID(id int64, assets []nativeRequests.Asset) (nativeRequests.Asset
func makeExt(httpInfo *httpCallInfo) *openrtb_ext.ExtHttpCall {
if httpInfo.err == nil {
return &openrtb_ext.ExtHttpCall{
Uri: httpInfo.request.Uri,
RequestBody: string(httpInfo.request.Body),
ResponseBody: string(httpInfo.response.Body),
Status: httpInfo.response.StatusCode,
Uri: httpInfo.request.Uri,
RequestBody: string(httpInfo.request.Body),
ResponseBody: string(httpInfo.response.Body),
Status: httpInfo.response.StatusCode,
RequestHeaders: httpInfo.request.Headers,
}
} else if httpInfo.request == nil {
return &openrtb_ext.ExtHttpCall{}
} else {
return &openrtb_ext.ExtHttpCall{
Uri: httpInfo.request.Uri,
RequestBody: string(httpInfo.request.Body),
Uri: httpInfo.request.Uri,
RequestBody: string(httpInfo.request.Body),
RequestHeaders: httpInfo.request.Headers,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log Request Headers when there is error

}
}
}
Expand Down
11 changes: 11 additions & 0 deletions exchange/bidder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ func TestBadRequestLogging(t *testing.T) {
if ext.Status != 0 {
t.Errorf("The Status code should be 0. Got %d", ext.Status)
}
if nil != ext.RequestHeaders || len(ext.RequestHeaders) > 0 {
t.Errorf("The request headers should be empty. Got %s", ext.RequestHeaders)
}
}

// TestBadResponseLogging makes sure that openrtb_ext works properly if we don't get a sensible HTTP response.
Expand All @@ -894,6 +897,9 @@ func TestBadResponseLogging(t *testing.T) {
request: &adapters.RequestData{
Uri: "test.com",
Body: []byte("request body"),
Headers: http.Header{
"header-1": []string{"value-1"},
},
Comment on lines +900 to +902
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simulation of request headers set

},
err: errors.New("Bad response"),
}
Expand All @@ -910,6 +916,7 @@ func TestBadResponseLogging(t *testing.T) {
if ext.Status != 0 {
t.Errorf("The Status code should be 0. Got %d", ext.Status)
}
assert.Equal(t, info.request.Headers, http.Header(ext.RequestHeaders), "The request headers should be \"header-1:value-1\"")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify Request headers are logged when there is a bad response

}

// TestSuccessfulResponseLogging makes sure that openrtb_ext works properly if the HTTP request is successful.
Expand All @@ -918,6 +925,9 @@ func TestSuccessfulResponseLogging(t *testing.T) {
request: &adapters.RequestData{
Uri: "test.com",
Body: []byte("request body"),
Headers: http.Header{
"header-1": []string{"value-1", "value-2"},
},
Comment on lines +928 to +930
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simulation of request headers set

},
response: &adapters.ResponseData{
StatusCode: 200,
Expand All @@ -937,6 +947,7 @@ func TestSuccessfulResponseLogging(t *testing.T) {
if ext.Status != info.response.StatusCode {
t.Errorf("The Status code should be 0. Got %d", ext.Status)
}
assert.Equal(t, info.request.Headers, http.Header(ext.RequestHeaders), "The request headers should be \"%s\". Got %s", info.request.Headers, ext.RequestHeaders)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify Request headers are logged when there is a bad response

}

func TestMobileNativeTypes(t *testing.T) {
Expand Down
10 changes: 7 additions & 3 deletions exchange/exchangetest/request-multi-bidders-debug-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
{
"uri": "appnexusTest.com",
"requestbody": "appnexusTestRequestBody",
"requestheaders": { "header_1" : ["value_11", "value_12"], "header_2" : ["value_21"] },
"responsebody": "appnexusTestResponseBody",
"status": 200
}
Expand Down Expand Up @@ -95,7 +96,8 @@
"uri": "audienceNetworkTest.com",
"requestbody": "audienceNetworkTestRequestBody",
"responsebody": "audienceNetworkTestResponseBody",
"status": 200
"status": 200,
"requestheaders": null
}
]
}
Expand Down Expand Up @@ -150,15 +152,17 @@
"uri": "appnexusTest.com",
"requestbody": "appnexusTestRequestBody",
"responsebody": "appnexusTestResponseBody",
"status": 200
"status": 200,
"requestheaders": { "header_1" : ["value_11", "value_12"], "header_2" : ["value_21"] }
}
],
"audienceNetwork": [
{
"uri": "audienceNetworkTest.com",
"requestbody": "audienceNetworkTestRequestBody",
"responsebody": "audienceNetworkTestResponseBody",
"status": 200
"status": 200,
"requestheaders": null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new parameter to satisfy the unit test

}
]
},
Expand Down
9 changes: 5 additions & 4 deletions openrtb_ext/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ type ExtBidderError struct {

// ExtHttpCall defines the contract for a bidresponse.ext.debug.httpcalls.{bidder}[i]
type ExtHttpCall struct {
Uri string `json:"uri"`
RequestBody string `json:"requestbody"`
ResponseBody string `json:"responsebody"`
Status int `json:"status"`
Uri string `json:"uri"`
RequestBody string `json:"requestbody"`
ResponseBody string `json:"responsebody"`
Status int `json:"status"`
RequestHeaders map[string][]string `json:"requestheaders"`
Copy link
Contributor Author

@ShriprasadM ShriprasadM Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new parameter RequestHeaders will contain the header key and multiple values associated with it.
We have kept value as an array of strings because one header can have multiple values.
Also, this data structure is inline with http/Header
requestheaders is the key used while forming the JSON

}

// CookieStatus describes the allowed values for bidresponse.ext.usersync.{bidder}.status
Expand Down