From 74ac069772e4a5e7e08b18bb7d05c62973252de1 Mon Sep 17 00:00:00 2001 From: antonbabak Date: Wed, 22 Jan 2025 10:29:55 +0100 Subject: [PATCH] Revert OptoutHandler changes --- .../org/prebid/server/cookie/UidsCookieService.java | 4 ++++ .../org/prebid/server/handler/OptoutHandler.java | 12 +++++------- .../org/prebid/server/handler/OptoutHandlerTest.java | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/prebid/server/cookie/UidsCookieService.java b/src/main/java/org/prebid/server/cookie/UidsCookieService.java index 3e2fe30d1ee..1fbbc2c51e6 100644 --- a/src/main/java/org/prebid/server/cookie/UidsCookieService.java +++ b/src/main/java/org/prebid/server/cookie/UidsCookieService.java @@ -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) diff --git a/src/main/java/org/prebid/server/handler/OptoutHandler.java b/src/main/java/org/prebid/server/handler/OptoutHandler.java index 38c93d68174..bc052654aec 100644 --- a/src/main/java/org/prebid/server/handler/OptoutHandler.java +++ b/src/main/java/org/prebid/server/handler/OptoutHandler.java @@ -68,7 +68,7 @@ private void handleVerification(RoutingContext routingContext, AsyncResult 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()); } @@ -102,14 +102,12 @@ private static boolean isOptout(RoutingContext routingContext) { return StringUtils.isNotEmpty(optoutValue); } - private List 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) { diff --git a/src/test/java/org/prebid/server/handler/OptoutHandlerTest.java b/src/test/java/org/prebid/server/handler/OptoutHandlerTest.java index a11d24b0133..adcdface038 100644 --- a/src/test/java/org/prebid/server/handler/OptoutHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/OptoutHandlerTest.java @@ -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));