Skip to content

Commit

Permalink
add support for the partitioned flg (CHIPS) on cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed May 3, 2024
1 parent b4f10d7 commit 9aaa73c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package kong.unirest.core;


import org.eclipse.jetty.http.CookieCutter;
import org.junit.jupiter.api.Test;

import java.time.ZoneId;
Expand Down Expand Up @@ -57,6 +55,12 @@ void alternateDate() {
c.getExpiration());
}

@Test
void partitionFlag() {
assertFalse(new Cookie("").isPartitioned());
assertTrue(new Cookie("color=blue;Partitioned;").isPartitioned());
}

@Test
void parseBackOutToString() {
String v = "color=blue;Path=/get;Domain=localhost;Expires=Sun, 05-Jan-2020 15:00:20 GMT;Max-Age=42;HttpOnly";
Expand All @@ -79,7 +83,6 @@ void secure() {
assertEquals("color=blue;Secure", c.toString());
}


@Test
void matchJettyParsing() {
String s = "_id=A528A0D64DA61CB01241EF6E18E4D675170DDB56CB430000AF58625E920CF940~pl1ZYwDDdoAnfY3RtqZ2Ti1MYOf7Q8jRrFQLneSGK7qQoUX1GHW/xDcqweGyclm5rm/g/YFCV3ohuHoz2oad5M0MX9Ru9V7bFr2s08d1lHxbn39gw71AI+ZVejq5FpMHKBzyjoBGG6NY6xYVTwP9NHo14SY0CXs60k2UTpJsOTNzAHIZaedg7o6R/8qyAQ8GF25K2o773pFLrYtjgKHohkk5ukz/yEGQitq8NgC5hiqX0=; expires=Fri, 06 Mar 2020 16:05:35 GMT; max-age=7200; path=/; domain=xxx.com; HttpOnly";
Expand Down
8 changes: 8 additions & 0 deletions unirest/src/main/java/kong/unirest/core/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class Cookie {
private ZonedDateTime expires;
private boolean secure;
private SameSite sameSite;
private boolean partitioned;

public Cookie(String name, String value){
this.name = name;
Expand Down Expand Up @@ -118,6 +119,9 @@ private void parseSection(String[] sub) {
httpOnly = true;
break;
}
case "partitioned":
partitioned = true;
break;
case "secure": {
secure = true;
break;
Expand Down Expand Up @@ -169,6 +173,10 @@ public void setHttpOnly(boolean httpOnly) {
this.httpOnly = httpOnly;
}

public boolean isPartitioned() {
return this.partitioned;
}

private static class Pair {
final String key;
final String value;
Expand Down

0 comments on commit 9aaa73c

Please sign in to comment.