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

[Sharethrough] Adapter fixes #1082

Merged
merged 3 commits into from
Oct 24, 2019
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
7 changes: 3 additions & 4 deletions adapters/sharethrough/butler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (s StrOpenRTBTranslator) requestFromOpenRTB(imp openrtb.Imp, request *openr
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
headers.Add("Accept-Encoding", "gzip")
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why is gzip no longer accepted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SyntaxNode it actually broke our adapter, our ad server now returns gzip encoded responses and it looks like the adapter needs to handle unzipping itself. We'll push a fix later to decode gzipped responses but for now we just need this fix asap in production as it can't process any bid in its current state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha.

headers.Add("Origin", domain)
headers.Add("Referer", request.Site.Page)
headers.Add("X-Forwarded-For", request.Device.IP)
Expand All @@ -90,7 +89,7 @@ func (s StrOpenRTBTranslator) requestFromOpenRTB(imp openrtb.Imp, request *openr
userInfo := s.Util.parseUserInfo(request.User)
height, width := s.Util.getPlacementSize(imp, strImpParams)

jsonBody, err := (StrBodyHelper{Clock: s.Util.getClock()}).buildBody(request, imp)
jsonBody, err := (StrBodyHelper{Clock: s.Util.getClock()}).buildBody(request, strImpParams)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -163,7 +162,7 @@ func (s StrOpenRTBTranslator) responseToOpenRTB(strRawResp []byte, btlrReq *adap
return bidResponse, errs
}

func (h StrBodyHelper) buildBody(request *openrtb.BidRequest, imp openrtb.Imp) (body []byte, err error) {
func (h StrBodyHelper) buildBody(request *openrtb.BidRequest, strImpParams openrtb_ext.ExtImpSharethrough) (body []byte, err error) {
timeout := request.TMax
if timeout == 0 {
timeout = defaultTmax
Expand All @@ -173,7 +172,7 @@ func (h StrBodyHelper) buildBody(request *openrtb.BidRequest, imp openrtb.Imp) (
BlockedAdvDomains: request.BAdv,
MaxTimeout: timeout,
Deadline: h.Clock.now().Add(time.Duration(timeout) * time.Millisecond).Format(time.RFC3339Nano),
BidFloor: imp.BidFloor,
BidFloor: strImpParams.BidFloor,
})

return
Expand Down
15 changes: 6 additions & 9 deletions adapters/sharethrough/butler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
"Generates the correct AdServer request from Imp (no user provided)": {
inputImp: openrtb.Imp{
ID: "abc",
Ext: []byte(`{ "bidder": {"pkey": "pkey", "iframe": true, "iframeSize": [10, 20]} }`),
Ext: []byte(`{ "bidder": {"pkey": "pkey", "iframe": true, "iframeSize": [10, 20], "bidfloor": 1.0} }`),
Banner: &openrtb.Banner{
Format: []openrtb.Format{{H: 30, W: 40}},
},
BidFloor: 1.0,
},
inputReq: &openrtb.BidRequest{
App: &openrtb.App{Ext: []byte(`{}`)},
Expand All @@ -106,7 +105,6 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
Headers: http.Header{
"Content-Type": []string{"application/json;charset=utf-8"},
"Accept": []string{"application/json"},
"Accept-Encoding": []string{"gzip"},
"Origin": []string{"http://a.domain.com"},
"Referer": []string{"http://a.domain.com/page"},
"User-Agent": []string{"Android Chome/60"},
Expand Down Expand Up @@ -140,7 +138,6 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
Headers: http.Header{
"Content-Type": []string{"application/json;charset=utf-8"},
"Accept": []string{"application/json"},
"Accept-Encoding": []string{"gzip"},
"Origin": []string{"http://a.domain.com"},
"Referer": []string{"http://a.domain.com/page"},
"User-Agent": []string{"Android Chome/60"},
Expand Down Expand Up @@ -379,35 +376,35 @@ func TestFailResponseToOpenRTB(t *testing.T) {
func TestBuildBody(t *testing.T) {
tests := map[string]struct {
inputRequest *openrtb.BidRequest
inputImp openrtb.Imp
inputImp openrtb_ext.ExtImpSharethrough
expectedJson []byte
expectedError error
}{
"Empty input: skips badomains, tmax default to 10 sec and sets deadline accordingly": {
inputRequest: &openrtb.BidRequest{},
inputImp: openrtb.Imp{},
inputImp: openrtb_ext.ExtImpSharethrough{},
expectedJson: []byte(`{"tmax":10000, "deadline":"2019-09-12T11:29:10.000123456Z"}`),
expectedError: nil,
},
"Sets badv as list of domains according to Badv (tmax default to 10 sec and sets deadline accordingly)": {
inputRequest: &openrtb.BidRequest{
BAdv: []string{"dom1.com", "dom2.com"},
},
inputImp: openrtb.Imp{},
inputImp: openrtb_ext.ExtImpSharethrough{},
expectedJson: []byte(`{"badv": ["dom1.com", "dom2.com"], "tmax":10000, "deadline":"2019-09-12T11:29:10.000123456Z"}`),
expectedError: nil,
},
"Sets tmax and deadline according to Tmax": {
inputRequest: &openrtb.BidRequest{
TMax: 500,
},
inputImp: openrtb.Imp{},
inputImp: openrtb_ext.ExtImpSharethrough{},
expectedJson: []byte(`{"tmax": 500, "deadline":"2019-09-12T11:29:00.500123456Z"}`),
expectedError: nil,
},
"Sets bidfloor according to the Imp object": {
inputRequest: &openrtb.BidRequest{},
inputImp: openrtb.Imp{
inputImp: openrtb_ext.ExtImpSharethrough{
BidFloor: 1.23,
},
expectedJson: []byte(`{"tmax":10000, "deadline":"2019-09-12T11:29:10.000123456Z", "bidfloor":1.23}`),
Expand Down
2 changes: 1 addition & 1 deletion adapters/sharethrough/sharethrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const supplyId = "FGMrCMMc"
const strVersion = 6
const strVersion = 7

func NewSharethroughBidder(endpoint string) *SharethroughAdapter {
return &SharethroughAdapter{
Expand Down
7 changes: 4 additions & 3 deletions openrtb_ext/imp_sharethrough.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package openrtb_ext

type ExtImpSharethrough struct {
Pkey string `json:"pkey"`
Iframe bool `json:"iframe"`
IframeSize []int `json:"iframeSize"`
Pkey string `json:"pkey"`
Iframe bool `json:"iframe"`
IframeSize []int `json:"iframeSize"`
BidFloor float64 `json:"bidfloor"`
}

// ExtImpSharethrough defines the contract for bidrequest.imp[i].ext.sharethrough
Expand Down
4 changes: 4 additions & 0 deletions static/bidder-params/sharethrough.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
},
"description": "iframe dimensions",
"default": [0, 0]
},
"bidfloor": {
"type": "number",
"description": "The floor price, or minimum amount, a publisher will accept for an impression, given in CPM in USD"
}
},
"required": ["pkey"]
Expand Down