Skip to content

Commit

Permalink
Admatic: Add headers (#4083)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakicam authored Jan 28, 2025
1 parent 1964dc7 commit aaac978
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 4 deletions.
25 changes: 21 additions & 4 deletions adapters/admatic/admatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
var requests []*adapters.RequestData
var errs []error

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
if request.Device != nil {
if len(request.Device.UA) > 0 {
headers.Add("User-Agent", request.Device.UA)
}

if len(request.Device.IPv6) > 0 {
headers.Add("X-Forwarded-For", request.Device.IPv6)
}

if len(request.Device.IP) > 0 {
headers.Add("X-Forwarded-For", request.Device.IP)
}
}
requestCopy := *request
for _, imp := range request.Imp {
requestCopy.Imp = []openrtb2.Imp{imp}
Expand All @@ -52,10 +68,11 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
}

request := &adapters.RequestData{
Method: http.MethodPost,
Body: requestJSON,
Uri: endpoint,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
Method: http.MethodPost,
Body: requestJSON,
Uri: endpoint,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
}

requests = append(requests, request)
Expand Down
26 changes: 26 additions & 0 deletions adapters/admatic/admatictest/exemplary/banner.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"mockBidRequest": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
Expand All @@ -24,9 +30,29 @@
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"123.123.123.123"
]
},
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
Expand Down
122 changes: 122 additions & 0 deletions adapters/admatic/admatictest/exemplary/headers_ipv4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"mockBidRequest": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"123.123.123.123"
]
},
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
]
},
"impIDs": ["test-imp-id-banner"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id-banner",
"seatbid": [
{
"seat": "admatic",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-banner",
"crid": "crid_10",
"w": 728,
"h": 90
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-banner",
"crid": "crid_10",
"w": 728,
"h": 90
},
"type": "banner"
}
]
}
]
}
123 changes: 123 additions & 0 deletions adapters/admatic/admatictest/exemplary/headers_ipv6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"mockBidRequest": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ipv6": "2607:fb90:f27:4512:d800:cb23:a603:e245",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"2607:fb90:f27:4512:d800:cb23:a603:e245"
]
},
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ipv6": "2607:fb90:f27:4512:d800:cb23:a603:e245",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
]
},
"impIDs": ["test-imp-id-banner"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id-banner",
"seatbid": [
{
"seat": "admatic",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-banner",
"crid": "crid_10",
"w": 728,
"h": 90
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-banner",
"crid": "crid_10",
"w": 728,
"h": 90
},
"type": "banner"
}
]
}
]
}

32 changes: 32 additions & 0 deletions adapters/admatic/admatictest/exemplary/multiple-imps.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"mockBidRequest": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
Expand Down Expand Up @@ -41,9 +47,29 @@
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"123.123.123.123"
]
},
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
Expand Down Expand Up @@ -95,6 +121,12 @@
"uri": "http://pbs.admatic.com.tr?host=layer2.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner2",
Expand Down
Loading

0 comments on commit aaac978

Please sign in to comment.