Skip to content

Commit

Permalink
Revert OptoutHandler changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic committed Jan 22, 2025
1 parent 917a57a commit 74ac069
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/prebid/server/cookie/UidsCookieService.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ public Cookie makeCookie(String cookieName, UidsCookie uidsCookie) {
.setDomain(hostCookieDomain);
}

public Cookie makeCookie(UidsCookie uidsCookie) {
return makeCookie(COOKIE_NAME, uidsCookie);
}

public Cookie removeCookie(String cookieName) {
return Cookie
.cookie(cookieName, StringUtils.EMPTY)
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/prebid/server/handler/OptoutHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void handleVerification(RoutingContext routingContext, AsyncResult<Recap
respondWithUnauthorized(routingContext, result.cause());
} else {
final boolean optout = isOptout(routingContext);
respondWithRedirectAndCookie(routingContext, optCookies(optout, routingContext), optUrl(optout));
respondWithRedirectAndCookie(routingContext, optCookie(optout, routingContext), optUrl(optout));
}
}

Expand All @@ -88,12 +88,12 @@ private void respondWithUnauthorized(RoutingContext routingContext, Throwable ex
.end());
}

private void respondWithRedirectAndCookie(RoutingContext routingContext, List<Cookie> cookies, String url) {
private void respondWithRedirectAndCookie(RoutingContext routingContext, Cookie cookie, String url) {
HttpUtil.executeSafely(routingContext, Endpoint.optout,
response -> response
.setStatusCode(HttpResponseStatus.MOVED_PERMANENTLY.code())
.putHeader(HttpUtil.LOCATION_HEADER, url)
.putHeader(HttpUtil.SET_COOKIE_HEADER.toString(), cookies.stream().map(Cookie::encode).toList())
.putHeader(HttpUtil.SET_COOKIE_HEADER, cookie.encode())
.end());
}

Expand All @@ -102,14 +102,12 @@ private static boolean isOptout(RoutingContext routingContext) {
return StringUtils.isNotEmpty(optoutValue);
}

private List<Cookie> optCookies(boolean optout, RoutingContext routingContext) {
private Cookie optCookie(boolean optout, RoutingContext routingContext) {
final UidsCookie uidsCookie = uidsCookieService
.parseFromRequest(routingContext)
.updateOptout(optout);

return uidsCookieService.splitUids(uidsCookie).entrySet().stream()
.map(entry -> uidsCookieService.makeCookie(entry.getKey(), entry.getValue()))
.toList();
return uidsCookieService.makeCookie(uidsCookie);
}

private String optUrl(boolean optout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setUp() {

given(googleRecaptchaVerifier.verify(anyString())).willReturn(Future.succeededFuture());

given(uidsCookieService.makeCookie(any(), any())).willReturn(Cookie.cookie("cookie", "value"));
given(uidsCookieService.makeCookie(any())).willReturn(Cookie.cookie("cookie", "value"));
given(uidsCookieService.parseFromRequest(any(RoutingContext.class)))
.willReturn(new UidsCookie(Uids.builder().uids(emptyMap()).build(), jacksonMapper));

Expand Down

0 comments on commit 74ac069

Please sign in to comment.