Fix #8294 push added cookie (#8298)

* Fix #8294 push added cookie

Reparse cookie added with addCookie
Added extra test to ensure maxAge is being parsed with other cookie attributes

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2022-07-19 03:39:40 +10:00 committed by GitHub
parent 69b851c6e6
commit 26a255e481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -352,7 +352,10 @@ public class Request implements HttpServletRequest
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

View File

@ -54,6 +54,7 @@ import org.eclipse.jetty.http.BadMessageException;
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;
@ -1965,6 +1966,8 @@ public class RequestTest
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", "duckling", 100).getSetCookie(CookieCompliance.RFC6265)));
request.getResponse().getHttpFields().add(new HttpField(HttpHeader.SET_COOKIE, "flow=away; Max-Age=0; Secure; HttpOnly; SameSite=None"));
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));
@ -1989,6 +1992,8 @@ public class RequestTest
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"));
assertThat(builder.getHeader("Cookie"), not(containsString("flown")));
}
@Test