Skip to content

Commit

Permalink
allow setting the Partitioned flag on cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed May 8, 2024
1 parent 4c53737 commit faf2c3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ void partitionFlag() {
assertTrue(new Cookie("color=blue;Partitioned;").isPartitioned());
}

@Test
void canSetPartition() {
var cookie = new Cookie("cookie", "snickerdoodle");
cookie.setPartitioned(true);
assertEquals("cookie=snickerdoodle;Partitioned", cookie.toString());
}

@Test
void canSetSecured() {
var cookie = new Cookie("cookie", "snickerdoodle");
cookie.setSecured(true);
assertEquals("cookie=snickerdoodle;Secure", cookie.toString());
}

@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 Down
11 changes: 11 additions & 0 deletions unirest/src/main/java/kong/unirest/core/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public String toString() {
if(secure){
pairs.add(new Pair("Secure", null));
}
if(partitioned){
pairs.add(new Pair("Partitioned", null));
}
return pairs.stream().map(Pair::toString).collect(Collectors.joining(";"));
}

Expand All @@ -177,6 +180,14 @@ public boolean isPartitioned() {
return this.partitioned;
}

public void setPartitioned(boolean value) {
this.partitioned = value;
}

public void setSecured(boolean value) {
this.secure = value;
}

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

0 comments on commit faf2c3f

Please sign in to comment.