Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
Jan Bartel 2020-05-28 11:14:11 +02:00
commit 46f8705b8c
2 changed files with 39 additions and 19 deletions

View File

@ -229,6 +229,9 @@ public class Response implements HttpServletResponse
@Override @Override
public void addCookie(Cookie cookie) public void addCookie(Cookie cookie)
{
//Servlet Spec 9.3 Include method: cannot set a cookie if handling an include
if (isMutable())
{ {
if (StringUtil.isBlank(cookie.getName())) if (StringUtil.isBlank(cookie.getName()))
throw new IllegalArgumentException("Cookie.name cannot be blank/null"); throw new IllegalArgumentException("Cookie.name cannot be blank/null");
@ -251,6 +254,7 @@ public class Response implements HttpServletResponse
cookie.getVersion(), cookie.getVersion(),
sameSite)); sameSite));
} }
}
/** /**
* Replace (or add) a cookie. * Replace (or add) a cookie.
@ -302,7 +306,6 @@ public class Response implements HttpServletResponse
addCookie(cookie); addCookie(cookie);
} }
@Override
public boolean containsHeader(String name) public boolean containsHeader(String name)
{ {
return _fields.contains(name); return _fields.contains(name);

View File

@ -1094,6 +1094,23 @@ public class ResponseTest
assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly", set); assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly", set);
} }
@Test
public void testAddCookieInInclude() throws Exception
{
Response response = getResponse();
response.include();
Cookie cookie = new Cookie("naughty", "value");
cookie.setDomain("domain");
cookie.setPath("/path");
cookie.setSecure(true);
cookie.setComment("comment__HTTP_ONLY__");
response.addCookie(cookie);
assertNull(response.getHttpFields().get("Set-Cookie"));
}
@Test @Test
public void testAddCookieSameSiteDefault() throws Exception public void testAddCookieSameSiteDefault() throws Exception
{ {