-
Notifications
You must be signed in to change notification settings - Fork 224
Multiple Uids Cookies Support #3668
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1efbc2e
Multiple Uids Cookies Support
AntoxaAntoxic f4df68f
Merge remote-tracking branch 'refs/remotes/origin/master' into multip…
AntoxaAntoxic b14ee5a
Fix compilation error
AntoxaAntoxic 917a57a
Removing cookie when uids are empty
AntoxaAntoxic 74ac069
Revert OptoutHandler changes
AntoxaAntoxic 361605a
Fix comments
AntoxaAntoxic db75507
Tests: Multiple Uids Cookies Support (#3691)
osulzhenko 2fd0b40
Cookie Size Calculation Optimization
AntoxaAntoxic 7405892
update functional tests
osulzhenko 7ff5ff4
Change size prediction logic (#3712)
CTMBNara 2a4e6dc
Merge remote-tracking branch 'refs/remotes/origin/master' into multip…
AntoxaAntoxic 9d75e13
Remove Unused Method
AntoxaAntoxic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/org/prebid/server/cookie/UidsCookieSize.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package org.prebid.server.cookie; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import io.vertx.core.http.Cookie; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.prebid.server.json.ObjectMapperProvider; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.ZoneId; | ||
| import java.time.ZonedDateTime; | ||
|
|
||
| public class UidsCookieSize { | ||
|
|
||
| // {"tempUIDs":{},"optout":false} | ||
| private static final int TEMP_UIDS_BASE64_BYTES = "eyJ0ZW1wVUlEcyI6e30sIm9wdG91dCI6ZmFsc2V9".length(); | ||
| private static final int UID_TEMPLATE_BYTES; | ||
|
|
||
| static { | ||
| try { | ||
| UID_TEMPLATE_BYTES = "\"\":{\"uid\":\"\",\"expires\":\"%s\"}," | ||
| .formatted(ObjectMapperProvider.mapper().writeValueAsString( | ||
| ZonedDateTime.ofInstant(Instant.ofEpochSecond(0, 1), ZoneId.of("UTC")))) | ||
| .length(); | ||
| } catch (JsonProcessingException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| private final int cookieSchemaSize; | ||
| private final int maxSize; | ||
| private int encodedUidsSize; | ||
|
|
||
| public UidsCookieSize(int cookieSchemaSize, int maxSize) { | ||
| this.cookieSchemaSize = cookieSchemaSize; | ||
| this.maxSize = maxSize; | ||
|
|
||
| encodedUidsSize = 0; | ||
| } | ||
|
|
||
| public static int schemaSize(Cookie cookieSchema) { | ||
| return cookieSchema.setValue(StringUtils.EMPTY).encode().length(); | ||
| } | ||
|
|
||
| public boolean isValid() { | ||
| return maxSize <= 0 || totalSize() <= maxSize; | ||
| } | ||
|
|
||
| public int totalSize() { | ||
| return cookieSchemaSize | ||
| + TEMP_UIDS_BASE64_BYTES | ||
| + Base64Size.base64Size(encodedUidsSize); | ||
| } | ||
|
|
||
| public void addUid(String cookieFamily, String uid) { | ||
| final int uidSize = UID_TEMPLATE_BYTES + cookieFamily.length() + uid.length(); | ||
| encodedUidsSize = Base64Size.encodeSize(Base64Size.decodeSize(encodedUidsSize) + uidSize); | ||
| } | ||
|
|
||
| private static class Base64Size { | ||
|
|
||
| public static int encodeSize(int size) { | ||
| return size / 3 * 4 + size % 3; | ||
| } | ||
|
|
||
| public static int decodeSize(int encodedSize) { | ||
| return encodedSize / 4 * 3 + encodedSize % 4; | ||
| } | ||
|
|
||
| private static int base64Size(int encodedSize) { | ||
| return (encodedSize & -4) + 4 * Integer.signum(encodedSize % 4); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.