Skip to content

Commit

Permalink
requestheaders: new parameter inside debug.httpcalls.<BIDDER> to log …
Browse files Browse the repository at this point in the history
…request header details (#1659)

* Added support for logging requestheaders inside httpCalls.requestheaders

* Reverterd test case change

* Modified outgoing mock request for appnexus, to send some request header information.
Modified sample mock response such that ext.debug.httpcalls.appnexus.requestheaders will return the information of passed request headers

* Addressed code review comments given by SyntaxNode.
Also Moved RequestHeaders next to RequestBidy in openrtb_ext.ExtHttpCall

Co-authored-by: Shriprasad <[email protected]>
  • Loading branch information
ShriprasadM and pm-shriprasad-marathe authored Jan 28, 2021
1 parent 54f22b2 commit 3793d4c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
14 changes: 8 additions & 6 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,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,
}
}
}
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 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"},
},
},
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\"")
}

// 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"},
},
},
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)
}

func TestMobileNativeTypes(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 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 @@ -94,6 +95,7 @@
{
"uri": "audienceNetworkTest.com",
"requestbody": "audienceNetworkTestRequestBody",
"requestheaders": null,
"responsebody": "audienceNetworkTestResponseBody",
"status": 200
}
Expand Down Expand Up @@ -149,6 +151,7 @@
{
"uri": "appnexusTest.com",
"requestbody": "appnexusTestRequestBody",
"requestheaders": { "header_1" : ["value_11", "value_12"], "header_2" : ["value_21"] },
"responsebody": "appnexusTestResponseBody",
"status": 200
}
Expand All @@ -157,6 +160,7 @@
{
"uri": "audienceNetworkTest.com",
"requestbody": "audienceNetworkTestRequestBody",
"requestheaders": null,
"responsebody": "audienceNetworkTestResponseBody",
"status": 200
}
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"`
RequestHeaders map[string][]string `json:"requestheaders"`
ResponseBody string `json:"responsebody"`
Status int `json:"status"`
}

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

0 comments on commit 3793d4c

Please sign in to comment.