Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Add scheme to Origin header + add X-Forwarded-For and User-Agent head…
Browse files Browse the repository at this point in the history
…ers (prebid#958)
  • Loading branch information
Mathieu Pheulpin authored and mansinahar committed Jul 17, 2019
1 parent 49c9809 commit 6f02596
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions adapters/sharethrough/butler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (s StrOpenRTBTranslator) requestFromOpenRTB(imp openrtb.Imp, request *openr
headers.Add("Content-Type", "text/plain;charset=utf-8")
headers.Add("Accept", "application/json")
headers.Add("Origin", domain)
headers.Add("X-Forwarded-For", request.Device.IP)
headers.Add("User-Agent", request.Device.UA)

var strImpExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &strImpExt); err != nil {
Expand Down
16 changes: 11 additions & 5 deletions adapters/sharethrough/butler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func assertRequestDataEquals(t *testing.T, testName string, expected *adapters.R
if len(expected.Body) != len(actual.Body) {
t.Errorf("Body mismatch: expected %s got %s\n", expected.Body, actual.Body)
}
if len(expected.Headers) != len(actual.Headers) {
t.Errorf("Number of headers mismatch: expected %d got %d\n", len(expected.Headers), len(actual.Headers))
}
for headerIndex, expectedHeader := range expected.Headers {
if expectedHeader[0] != actual.Headers[headerIndex][0] {
t.Errorf("Header %s mismatch: expected %s got %s\n", headerIndex, expectedHeader[0], actual.Headers[headerIndex][0])
Expand All @@ -78,17 +81,20 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
App: &openrtb.App{Ext: []byte(`{}`)},
Device: &openrtb.Device{
UA: "Android Chome/60",
IP: "127.0.0.1",
},
},
inputDom: "a.domain.com",
inputDom: "http://a.domain.com",
expected: &adapters.RequestData{
Method: "POST",
Uri: "http://abc.com",
Body: nil,
Headers: http.Header{
"Content-Type": []string{"text/plain;charset=utf-8"},
"Accept": []string{"application/json"},
"Origin": []string{"a.domain.com"},
"Content-Type": []string{"text/plain;charset=utf-8"},
"Accept": []string{"application/json"},
"Origin": []string{"http://a.domain.com"},
"User-Agent": []string{"Android Chome/60"},
"X-Forwarded-For": []string{"127.0.0.1"},
},
},
},
Expand Down Expand Up @@ -290,7 +296,7 @@ func TestBuildUri(t *testing.T) {
"height=20",
"width=30",
"supplyId=FGMrCMMc",
"strVersion=1.0.0",
"strVersion=" + strVersion,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/sharethrough/sharethrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const supplyId = "FGMrCMMc"
const strVersion = "1.0.0"
const strVersion = "1.0.1"

func NewSharethroughBidder(endpoint string) *SharethroughAdapter {
return &SharethroughAdapter{
Expand Down
4 changes: 4 additions & 0 deletions adapters/sharethrough/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ func (u Util) parseDomain(fullUrl string) string {
} else {
domain = uri.Host
}

if domain != "" {
domain = uri.Scheme + "://" + domain
}
}

return domain
Expand Down
6 changes: 3 additions & 3 deletions adapters/sharethrough/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,11 @@ func TestParseDomain(t *testing.T) {
}{
"Parses domain without port": {
input: "http://a.domain.com/page?param=value",
expected: "a.domain.com",
expected: "http://a.domain.com",
},
"Parses domain with port": {
input: "http://a.domain.com:8000/page?param=value",
expected: "a.domain.com",
input: "https://a.domain.com:8000/page?param=value",
expected: "https://a.domain.com",
},
"Returns empty string if cannot parse the domain": {
input: "abc",
Expand Down

0 comments on commit 6f02596

Please sign in to comment.