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

Commit 6f02596

Browse files
Mathieu Pheulpinmansinahar
authored andcommitted
Add scheme to Origin header + add X-Forwarded-For and User-Agent headers (prebid#958)
1 parent 49c9809 commit 6f02596

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

adapters/sharethrough/butler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func (s StrOpenRTBTranslator) requestFromOpenRTB(imp openrtb.Imp, request *openr
5555
headers.Add("Content-Type", "text/plain;charset=utf-8")
5656
headers.Add("Accept", "application/json")
5757
headers.Add("Origin", domain)
58+
headers.Add("X-Forwarded-For", request.Device.IP)
59+
headers.Add("User-Agent", request.Device.UA)
5860

5961
var strImpExt adapters.ExtImpBidder
6062
if err := json.Unmarshal(imp.Ext, &strImpExt); err != nil {

adapters/sharethrough/butler_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func assertRequestDataEquals(t *testing.T, testName string, expected *adapters.R
5252
if len(expected.Body) != len(actual.Body) {
5353
t.Errorf("Body mismatch: expected %s got %s\n", expected.Body, actual.Body)
5454
}
55+
if len(expected.Headers) != len(actual.Headers) {
56+
t.Errorf("Number of headers mismatch: expected %d got %d\n", len(expected.Headers), len(actual.Headers))
57+
}
5558
for headerIndex, expectedHeader := range expected.Headers {
5659
if expectedHeader[0] != actual.Headers[headerIndex][0] {
5760
t.Errorf("Header %s mismatch: expected %s got %s\n", headerIndex, expectedHeader[0], actual.Headers[headerIndex][0])
@@ -78,17 +81,20 @@ func TestSuccessRequestFromOpenRTB(t *testing.T) {
7881
App: &openrtb.App{Ext: []byte(`{}`)},
7982
Device: &openrtb.Device{
8083
UA: "Android Chome/60",
84+
IP: "127.0.0.1",
8185
},
8286
},
83-
inputDom: "a.domain.com",
87+
inputDom: "http://a.domain.com",
8488
expected: &adapters.RequestData{
8589
Method: "POST",
8690
Uri: "http://abc.com",
8791
Body: nil,
8892
Headers: http.Header{
89-
"Content-Type": []string{"text/plain;charset=utf-8"},
90-
"Accept": []string{"application/json"},
91-
"Origin": []string{"a.domain.com"},
93+
"Content-Type": []string{"text/plain;charset=utf-8"},
94+
"Accept": []string{"application/json"},
95+
"Origin": []string{"http://a.domain.com"},
96+
"User-Agent": []string{"Android Chome/60"},
97+
"X-Forwarded-For": []string{"127.0.0.1"},
9298
},
9399
},
94100
},
@@ -290,7 +296,7 @@ func TestBuildUri(t *testing.T) {
290296
"height=20",
291297
"width=30",
292298
"supplyId=FGMrCMMc",
293-
"strVersion=1.0.0",
299+
"strVersion=" + strVersion,
294300
},
295301
},
296302
}

adapters/sharethrough/sharethrough.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
const supplyId = "FGMrCMMc"
15-
const strVersion = "1.0.0"
15+
const strVersion = "1.0.1"
1616

1717
func NewSharethroughBidder(endpoint string) *SharethroughAdapter {
1818
return &SharethroughAdapter{

adapters/sharethrough/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ func (u Util) parseDomain(fullUrl string) string {
206206
} else {
207207
domain = uri.Host
208208
}
209+
210+
if domain != "" {
211+
domain = uri.Scheme + "://" + domain
212+
}
209213
}
210214

211215
return domain

adapters/sharethrough/utils_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ func TestParseDomain(t *testing.T) {
416416
}{
417417
"Parses domain without port": {
418418
input: "http://a.domain.com/page?param=value",
419-
expected: "a.domain.com",
419+
expected: "http://a.domain.com",
420420
},
421421
"Parses domain with port": {
422-
input: "http://a.domain.com:8000/page?param=value",
423-
expected: "a.domain.com",
422+
input: "https://a.domain.com:8000/page?param=value",
423+
expected: "https://a.domain.com",
424424
},
425425
"Returns empty string if cannot parse the domain": {
426426
input: "abc",

0 commit comments

Comments
 (0)