Skip to content

Commit

Permalink
Fix #8294 push added cookie
Browse files Browse the repository at this point in the history
Reparse cookie added with addCookie

Signed-off-by: Greg Wilkins <[email protected]>
  • Loading branch information
gregw committed Jul 13, 2022
1 parent c1c2bdb commit 9e10d44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ public PushBuilder newPushBuilder()
HttpHeader header = field.getHeader();
if (header == HttpHeader.SET_COOKIE)
{
HttpCookie cookie = ((SetCookieHttpField)field).getHttpCookie();
HttpCookie cookie = (field instanceof SetCookieHttpField)
? ((SetCookieHttpField)field).getHttpCookie()
: new HttpCookie(field.getValue());

if (cookie.getMaxAge() > 0)
cookies.put(cookie.getName(), cookie.getValue());
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.eclipse.jetty.http.CookieCompliance;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpTester;
Expand Down Expand Up @@ -1965,6 +1966,7 @@ public void testPushBuilder()
request.getResponse().getHttpFields().add(new HttpCookie.SetCookieHttpField(new HttpCookie("good", "thumbsup", 100), CookieCompliance.RFC6265));
request.getResponse().getHttpFields().add(new HttpCookie.SetCookieHttpField(new HttpCookie("bonza", "bewdy", 1), CookieCompliance.RFC6265));
request.getResponse().getHttpFields().add(new HttpCookie.SetCookieHttpField(new HttpCookie("bad", "thumbsdown", 0), CookieCompliance.RFC6265));
request.getResponse().getHttpFields().add(new HttpField(HttpHeader.SET_COOKIE, new HttpCookie("ugly", "thumbsdown", 100).getSetCookie(CookieCompliance.RFC6265)));
HttpFields.Mutable fields = HttpFields.build();
fields.add(HttpHeader.AUTHORIZATION, "Basic foo");
request.setMetaData(new MetaData.Request("GET", HttpURI.from(uri), HttpVersion.HTTP_1_0, fields));
Expand All @@ -1989,6 +1991,7 @@ public void testPushBuilder()
assertThat(builder.getHeader("Cookie"), containsString("good"));
assertThat(builder.getHeader("Cookie"), containsString("maxpos"));
assertThat(builder.getHeader("Cookie"), not(containsString("bad")));
assertThat(builder.getHeader("Cookie"), containsString("ugly"));
}

@Test
Expand Down

0 comments on commit 9e10d44

Please sign in to comment.