-
Notifications
You must be signed in to change notification settings - Fork 731
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
GPC: Set extension based on header #3895
Changes from 1 commit
8971a36
58aab7c
b7692d7
a2b7cf1
c7fbfe1
f713ff1
5fba3db
f8e7977
b5acce3
bff49e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,10 +63,11 @@ const observeBrowsingTopics = "Observe-Browsing-Topics" | |
const observeBrowsingTopicsValue = "?1" | ||
|
||
var ( | ||
dntKey string = http.CanonicalHeaderKey("DNT") | ||
dntDisabled int8 = 0 | ||
dntEnabled int8 = 1 | ||
notAmp int8 = 0 | ||
dntKey string = http.CanonicalHeaderKey("DNT") | ||
secGPCHdrKey string = http.CanonicalHeaderKey("Sec-GPC") | ||
dntDisabled int8 = 0 | ||
dntEnabled int8 = 1 | ||
notAmp int8 = 0 | ||
) | ||
|
||
var accountIdSearchPath = [...]struct { | ||
|
@@ -1522,7 +1523,7 @@ func setAuctionTypeImplicitly(r *openrtb_ext.RequestWrapper) { | |
} | ||
|
||
func setGPCImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper) error { | ||
secGPC := httpReq.Header.Get("Sec-GPC") | ||
secGPC := httpReq.Header.Get(secGPCHdrKey) | ||
fmt.Printf("Sec-GPC Header: %s\n", secGPC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove print statement |
||
|
||
if secGPC != "1" { | ||
|
@@ -1538,6 +1539,20 @@ func setGPCImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper) erro | |
regExt.SetGPC(&gpc) | ||
fmt.Printf("GPC set to: %s\n", *regExt.GetGPC()) | ||
|
||
// Ręczna aktualizacja pola Regs.Ext | ||
regExtBytes, err := json.Marshal(regExt) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Debugging - sprawdzenie, co jest w regExtBytes | ||
fmt.Printf("Zawartość regExtBytes przed przypisaniem: %s\n", string(regExtBytes)) | ||
|
||
r.BidRequest.Regs.Ext = regExtBytes // Zaktualizowanie pola Regs.Ext | ||
|
||
// Debugging - sprawdzenie, co jest w r.BidRequest.Regs.Ext | ||
fmt.Printf("Zaktualizowane Regs.Ext: %s\n", string(r.BidRequest.Regs.Ext)) | ||
|
||
return nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5620,44 +5620,53 @@ func TestValidateOrFillCookieDeprecation(t *testing.T) { | |
|
||
func TestSetGPCImplicitly(t *testing.T) { | ||
testCases := []struct { | ||
description string | ||
headerValue string | ||
expectedGPC string | ||
expectError bool | ||
description string | ||
headerValue string | ||
expectedGPC string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this because |
||
expectError bool | ||
regs *openrtb2.Regs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: move |
||
expectedRegs *openrtb2.Regs | ||
}{ | ||
{ | ||
description: "Sec-GPC header set to '1', GPC should be set to '1'", | ||
przemkaczmarek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
headerValue: "1", | ||
expectedGPC: "1", | ||
expectError: false, | ||
regs: &openrtb2.Regs{ | ||
Ext: []byte(`{}`), | ||
}, | ||
expectedRegs: &openrtb2.Regs{ | ||
Ext: []byte(`{"gpc":"1"}`), | ||
}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to add these two test cases to ensure that we don't create a regs or regs.ext object if we're not writing to the
|
||
} | ||
|
||
for _, test := range testCases { | ||
t.Run(test.description, func(t *testing.T) { | ||
httpReq := &http.Request{ | ||
Header: http.Header{ | ||
"Sec-GPC": []string{test.headerValue}, | ||
http.CanonicalHeaderKey("Sec-GPC"): []string{test.headerValue}, | ||
}, | ||
} | ||
|
||
r := &openrtb_ext.RequestWrapper{ | ||
BidRequest: &openrtb2.BidRequest{}, // what I should add here??? | ||
BidRequest: &openrtb2.BidRequest{ | ||
Regs: test.regs, | ||
}, | ||
} | ||
|
||
// Wywołanie funkcji testowanej | ||
err := setGPCImplicitly(httpReq, r) | ||
if (err != nil) != test.expectError { | ||
t.Errorf("Unexpected error state: got %v, expected error: %v", err, test.expectError) | ||
} | ||
|
||
regExt, _ := r.GetRegExt() | ||
gpcValue := regExt.GetGPC() | ||
|
||
if gpcValue != nil && *gpcValue != test.expectedGPC { | ||
t.Errorf("Expected GPC %v, but got %v", test.expectedGPC, *gpcValue) | ||
} else if gpcValue == nil && test.expectedGPC != "" { | ||
t.Errorf("Expected GPC to be set, but it was nil") | ||
// Weryfikacja błędu | ||
if test.expectError { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
|
||
// Weryfikacja JSON | ||
assert.JSONEq(t, string(test.expectedRegs.Ext), string(r.BidRequest.Regs.Ext)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to handle the two new test cases I requested you can modify this as such:
|
||
}) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
secGPCKey
suffices