Skip to content

Commit f742272

Browse files
munchadtbarne
authored andcommitted
beachfront: Changes to support real 204 (prebid#1737)
1 parent 67d5299 commit f742272

15 files changed

+290
-21
lines changed

adapters/adapterstest/test_json.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func runSpec(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidd
123123
diffErrorLists(t, fmt.Sprintf("%s: MakeBids", filename), bidsErrs, spec.MakeBidsErrors)
124124

125125
for i := 0; i < len(spec.BidResponses); i++ {
126-
diffBidLists(t, filename, bidResponses[i].Bids, spec.BidResponses[i].Bids)
126+
diffBidLists(t, filename, bidResponses[i], spec.BidResponses[i].Bids)
127127
}
128128
}
129129

@@ -227,9 +227,24 @@ func diffErrorLists(t *testing.T, description string, actual []error, expected [
227227
}
228228
}
229229

230-
func diffBidLists(t *testing.T, filename string, actual []*adapters.TypedBid, expected []expectedBid) {
230+
func diffBidLists(t *testing.T, filename string, response *adapters.BidderResponse, expected []expectedBid) {
231231
t.Helper()
232232

233+
if (response == nil || len(response.Bids) == 0) != (len(expected) == 0) {
234+
if len(expected) == 0 {
235+
t.Fatalf("%s: expectedBidResponses indicated a nil response, but mockResponses supplied a non-nil response", filename)
236+
}
237+
238+
t.Fatalf("%s: mockResponses included unexpected nil or empty response", filename)
239+
}
240+
241+
// Expected nil response - give diffBids something to work with.
242+
if response == nil {
243+
response = new(adapters.BidderResponse)
244+
}
245+
246+
actual := response.Bids
247+
233248
if len(actual) != len(expected) {
234249
t.Fatalf("%s: MakeBids returned wrong bid count. Expected %d, got %d", filename, len(expected), len(actual))
235250
}

adapters/beachfront/beachfront.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type beachfrontBannerRequest struct {
7676
AdapterVersion string `json:"adapterVersion"`
7777
IP string `json:"ip"`
7878
RequestID string `json:"requestId"`
79+
Real204 bool `json:"real204"`
7980
}
8081

8182
type beachfrontSlot struct {
@@ -367,6 +368,7 @@ func getBannerRequest(request *openrtb.BidRequest) (beachfrontBannerRequest, []e
367368
if request.Imp[0].Secure != nil {
368369
bfr.Secure = *request.Imp[0].Secure
369370
}
371+
bfr.Real204 = true
370372

371373
return bfr, errs
372374
}
@@ -465,7 +467,7 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, []
465467
}
466468

467469
bfReqs[i].Request.Imp = nil
468-
bfReqs[i].Request.Imp = make([]openrtb.Imp, 1, 1)
470+
bfReqs[i].Request.Imp = make([]openrtb.Imp, 1)
469471
bfReqs[i].Request.Imp[0] = imp
470472

471473
}
@@ -481,18 +483,12 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, []
481483
}
482484

483485
func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
484-
var bids []openrtb.Bid
485-
486-
// The case of response status == 200 and response body length == 2 below covers the case of the banner endpoint returning
487-
// an empty JSON array ('[]'), which is functionally no content.
488-
if response.StatusCode == http.StatusNoContent || (response.StatusCode == http.StatusOK && len(response.Body) <= 2) {
489-
return nil, []error{&errortypes.BadInput{
490-
Message: fmt.Sprintf("no content or truncated content received from server. status code %d from %s. Run with request.debug = 1 for more info", response.StatusCode, externalRequest.Uri),
491-
}}
486+
if response.StatusCode == http.StatusNoContent {
487+
return nil, nil
492488
}
493489

494490
if response.StatusCode >= http.StatusInternalServerError {
495-
return nil, []error{&errortypes.BadInput{
491+
return nil, []error{&errortypes.BadServerResponse{
496492
Message: fmt.Sprintf("server error status code %d from %s. Run with request.debug = 1 for more info", response.StatusCode, externalRequest.Uri),
497493
}}
498494
}
@@ -507,8 +503,9 @@ func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern
507503
return nil, []error{fmt.Errorf("unexpected status code %d from %s. Run with request.debug = 1 for more info", response.StatusCode, externalRequest.Uri)}
508504
}
509505

510-
var xtrnal openrtb.BidRequest
506+
var bids []openrtb.Bid
511507
var errs = make([]error, 0)
508+
var xtrnal openrtb.BidRequest
512509

513510
// For video, which uses RTB for the external request, this will unmarshal as expected. For banner, it will
514511
// only get the User struct and everything else will be nil
@@ -524,6 +521,7 @@ func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern
524521

525522
var dur beachfrontVideoBidExtension
526523
bidResponse := adapters.NewBidderResponseWithBidsCapacity(BidCapacity)
524+
527525
for i := 0; i < len(bids); i++ {
528526

529527
// If we unmarshal without an error, this is an AdM video

adapters/beachfront/beachfronttest/exemplary/adm-video.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696

9797
"expectedBidResponses": [
9898
{
99+
"currency": "USD",
99100
"bids": [
100101
{
101102
"bid": {

adapters/beachfront/beachfronttest/exemplary/banner.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
],
4646
"domain": "some.domain.us",
4747
"page": "https://some.domain.us/some/page.html",
48+
"real204": true,
4849
"referrer": "",
4950
"search": "",
5051
"secure": 1,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "some_test_ad",
4+
"site": {
5+
"page": "https://some.domain.us/some/page.html"
6+
},
7+
"imp": [
8+
{
9+
"id": "dudImp",
10+
"bidfloor": 0.02,
11+
"banner": {
12+
"format": [
13+
{
14+
"w": 300,
15+
"h": 250
16+
}
17+
]
18+
},
19+
"ext": {
20+
"bidder": {
21+
"bidfloor": 0.02,
22+
"appId": "dudAppId1"
23+
}
24+
}
25+
}
26+
]
27+
},
28+
29+
"httpCalls": [
30+
{
31+
"expectedRequest": {
32+
"uri": "https://qa.beachrtb.com/prebid_display",
33+
"body": {
34+
"slots": [
35+
{
36+
"slot": "dudImp",
37+
"id": "dudAppId1",
38+
"bidfloor": 0.02,
39+
"sizes": [
40+
{
41+
"w": 300,
42+
"h": 250
43+
}
44+
]
45+
}
46+
],
47+
"domain": "some.domain.us",
48+
"page": "https://some.domain.us/some/page.html",
49+
"real204": true,
50+
"referrer": "",
51+
"search": "",
52+
"secure": 1,
53+
"requestId": "some_test_ad",
54+
"isMobile": 0,
55+
"ip": "",
56+
"deviceModel": "",
57+
"deviceOs": "",
58+
"dnt": 0,
59+
"ua": "",
60+
"adapterName": "BF_PREBID_S2S",
61+
"adapterVersion": "0.9.2",
62+
"user": {
63+
}
64+
}
65+
},
66+
"mockResponse": {
67+
"status": 204,
68+
"body": [
69+
{
70+
"something": "where nothing should be"
71+
}
72+
]
73+
}
74+
}
75+
],
76+
77+
"expectedBidResponses": []
78+
}
79+

adapters/beachfront/beachfronttest/supplemental/banner-empty_array-200.json renamed to adapters/beachfront/beachfronttest/supplemental/banner-204.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
],
4747
"domain": "some.domain.us",
4848
"page": "https://some.domain.us/some/page.html",
49+
"real204": true,
4950
"referrer": "",
5051
"search": "",
5152
"secure": 1,
@@ -63,18 +64,13 @@
6364
}
6465
},
6566
"mockResponse": {
66-
"status": 200,
67-
"body": []
67+
"status": 204,
68+
"body": ""
6869
}
6970
}
7071
],
7172

72-
"expectedBidResponses": [],
73+
"expectedBidResponses": [
7374

74-
"expectedMakeBidsErrors": [
75-
{
76-
"value": "no content or truncated content received from server. status code 200 from https://qa.beachrtb.com/prebid_display. Run with request.debug = 1 for more info",
77-
"comparison": "literal"
78-
}
7975
]
8076
}

adapters/beachfront/beachfronttest/supplemental/banner-and-adm-video-by-explicit.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
],
6161
"domain": "some.domain.us",
6262
"page": "https://some.domain.us/some/page.html",
63+
"real204": true,
6364
"referrer": "",
6465
"search": "",
6566
"secure": 1,

0 commit comments

Comments
 (0)