Skip to content
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

beachfront: Changes to support real 204 #1737

Merged
merged 16 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 17 additions & 2 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func runSpec(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidd
diffErrorLists(t, fmt.Sprintf("%s: MakeBids", filename), bidsErrs, spec.MakeBidsErrors)

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

Expand Down Expand Up @@ -227,9 +227,24 @@ func diffErrorLists(t *testing.T, description string, actual []error, expected [
}
}

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

if (response == nil || len(response.Bids) == 0) != (len(expected) == 0) {
if len(expected) == 0 {
t.Fatalf("%s: expectedBidResponses indicated a nil response, but mockResponses supplied a non-nil response", filename)
}

t.Fatalf("%s: mockResponses included unexpected nil or empty response", filename)
}

// Expected nil response - give diffBids something to work with.
if response == nil {
response = new(adapters.BidderResponse)
}

actual := response.Bids

if len(actual) != len(expected) {
t.Fatalf("%s: MakeBids returned wrong bid count. Expected %d, got %d", filename, len(expected), len(actual))
}
Expand Down
20 changes: 9 additions & 11 deletions adapters/beachfront/beachfront.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type beachfrontBannerRequest struct {
AdapterVersion string `json:"adapterVersion"`
IP string `json:"ip"`
RequestID string `json:"requestId"`
Real204 bool `json:"real204"`
}

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

return bfr, errs
}
Expand Down Expand Up @@ -465,7 +467,7 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, []
}

bfReqs[i].Request.Imp = nil
bfReqs[i].Request.Imp = make([]openrtb.Imp, 1, 1)
bfReqs[i].Request.Imp = make([]openrtb.Imp, 1)
bfReqs[i].Request.Imp[0] = imp

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

func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var bids []openrtb.Bid

// The case of response status == 200 and response body length == 2 below covers the case of the banner endpoint returning
// an empty JSON array ('[]'), which is functionally no content.
if response.StatusCode == http.StatusNoContent || (response.StatusCode == http.StatusOK && len(response.Body) <= 2) {
return nil, []error{&errortypes.BadInput{
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),
}}
if response.StatusCode == http.StatusNoContent {
return nil, nil
}

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

var xtrnal openrtb.BidRequest
var bids []openrtb.Bid
var errs = make([]error, 0)
var xtrnal openrtb.BidRequest

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

var dur beachfrontVideoBidExtension
bidResponse := adapters.NewBidderResponseWithBidsCapacity(BidCapacity)

for i := 0; i < len(bids); i++ {

// If we unmarshal without an error, this is an AdM video
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
Expand Down
1 change: 1 addition & 0 deletions adapters/beachfront/beachfronttest/exemplary/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
],
"domain": "some.domain.us",
"page": "https://some.domain.us/some/page.html",
"real204": true,
"referrer": "",
"search": "",
"secure": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"mockBidRequest": {
"id": "some_test_ad",
"site": {
"page": "https://some.domain.us/some/page.html"
},
"imp": [
{
"id": "dudImp",
"bidfloor": 0.02,
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"bidfloor": 0.02,
"appId": "dudAppId1"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "https://qa.beachrtb.com/prebid_display",
"body": {
"slots": [
{
"slot": "dudImp",
"id": "dudAppId1",
"bidfloor": 0.02,
"sizes": [
{
"w": 300,
"h": 250
}
]
}
],
"domain": "some.domain.us",
"page": "https://some.domain.us/some/page.html",
"real204": true,
"referrer": "",
"search": "",
"secure": 1,
"requestId": "some_test_ad",
"isMobile": 0,
"ip": "",
"deviceModel": "",
"deviceOs": "",
"dnt": 0,
"ua": "",
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"user": {
}
}
},
"mockResponse": {
"status": 204,
"body": [
{
"something": "where nothing should be"
}
]
}
}
],

"expectedBidResponses": []
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
],
"domain": "some.domain.us",
"page": "https://some.domain.us/some/page.html",
"real204": true,
"referrer": "",
"search": "",
"secure": 1,
Expand All @@ -63,18 +64,13 @@
}
},
"mockResponse": {
"status": 200,
"body": []
"status": 204,
"body": ""
}
}
],

"expectedBidResponses": [],
"expectedBidResponses": [

"expectedMakeBidsErrors": [
{
"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",
"comparison": "literal"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
],
"domain": "some.domain.us",
"page": "https://some.domain.us/some/page.html",
"real204": true,
"referrer": "",
"search": "",
"secure": 1,
Expand Down
Loading