Add space before cookie attributes
According to RFC-6265 that there should be a space between the ; and the attribute name, i.e. the header should be something like name=value; Domain=localhost; HttpOnly rather than name=value;Domain=localhost;HttpOnly Issue: SPR-15225
This commit is contained in:
parent
abe3cfd8de
commit
6e71828a35
|
|
@ -328,25 +328,25 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(cookie.getName()).append('=').append(cookie.getValue() == null ? "" : cookie.getValue());
|
||||
if (StringUtils.hasText(cookie.getPath())) {
|
||||
buf.append(";Path=").append(cookie.getPath());
|
||||
buf.append("; Path=").append(cookie.getPath());
|
||||
}
|
||||
if (StringUtils.hasText(cookie.getDomain())) {
|
||||
buf.append(";Domain=").append(cookie.getDomain());
|
||||
buf.append("; Domain=").append(cookie.getDomain());
|
||||
}
|
||||
int maxAge = cookie.getMaxAge();
|
||||
if (maxAge >= 0) {
|
||||
buf.append(";Max-Age=").append(maxAge);
|
||||
buf.append(";Expires=");
|
||||
buf.append("; Max-Age=").append(maxAge);
|
||||
buf.append("; Expires=");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setExpires(maxAge > 0 ? System.currentTimeMillis() + 1000L * maxAge : 0);
|
||||
buf.append(headers.getFirst(HttpHeaders.EXPIRES));
|
||||
}
|
||||
|
||||
if (cookie.getSecure()) {
|
||||
buf.append(";Secure");
|
||||
buf.append("; Secure");
|
||||
}
|
||||
if (cookie.isHttpOnly()) {
|
||||
buf.append(";HttpOnly");
|
||||
buf.append("; HttpOnly");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,9 +168,9 @@ public class MockHttpServletResponseTests {
|
|||
|
||||
response.addCookie(cookie);
|
||||
|
||||
assertEquals("foo=bar;Path=/path;Domain=example.com;" +
|
||||
"Max-Age=0;Expires=Thu, 01 Jan 1970 00:00:00 GMT;" +
|
||||
"Secure;HttpOnly", response.getHeader(HttpHeaders.SET_COOKIE));
|
||||
assertEquals("foo=bar; Path=/path; Domain=example.com; " +
|
||||
"Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; " +
|
||||
"Secure; HttpOnly", response.getHeader(HttpHeaders.SET_COOKIE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ public class MockWebResponseBuilderTests {
|
|||
assertThat(header.getValue(), equalTo("value"));
|
||||
header = responseHeaders.get(2);
|
||||
assertThat(header.getName(), equalTo("Set-Cookie"));
|
||||
assertThat(header.getValue(), startsWith("cookieA=valueA;Path=/path;Domain=domain;Max-Age=1800;Expires="));
|
||||
assertThat(header.getValue(), endsWith(";Secure;HttpOnly"));
|
||||
assertThat(header.getValue(), startsWith("cookieA=valueA; Path=/path; Domain=domain; Max-Age=1800; Expires="));
|
||||
assertThat(header.getValue(), endsWith("; Secure; HttpOnly"));
|
||||
}
|
||||
|
||||
// SPR-14169
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class PrintingResultHandlerTests {
|
|||
assertEquals(2, cookieValues.size());
|
||||
assertEquals("cookie=cookieValue", cookieValues.get(0));
|
||||
assertTrue("Actual: " + cookieValues.get(1), cookieValues.get(1).startsWith(
|
||||
"enigma=42;Path=/crumbs;Domain=.example.com;Max-Age=1234;Expires="));
|
||||
"enigma=42; Path=/crumbs; Domain=.example.com; Max-Age=1234; Expires="));
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("header", "headerValue");
|
||||
|
|
|
|||
|
|
@ -328,25 +328,25 @@ public class MockHttpServletResponse implements HttpServletResponse {
|
|||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(cookie.getName()).append('=').append(cookie.getValue() == null ? "" : cookie.getValue());
|
||||
if (StringUtils.hasText(cookie.getPath())) {
|
||||
buf.append(";Path=").append(cookie.getPath());
|
||||
buf.append("; Path=").append(cookie.getPath());
|
||||
}
|
||||
if (StringUtils.hasText(cookie.getDomain())) {
|
||||
buf.append(";Domain=").append(cookie.getDomain());
|
||||
buf.append("; Domain=").append(cookie.getDomain());
|
||||
}
|
||||
int maxAge = cookie.getMaxAge();
|
||||
if (maxAge >= 0) {
|
||||
buf.append(";Max-Age=").append(maxAge);
|
||||
buf.append(";Expires=");
|
||||
buf.append("; Max-Age=").append(maxAge);
|
||||
buf.append("; Expires=");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setExpires(maxAge > 0 ? System.currentTimeMillis() + 1000L * maxAge : 0);
|
||||
buf.append(headers.getFirst(HttpHeaders.EXPIRES));
|
||||
}
|
||||
|
||||
if (cookie.getSecure()) {
|
||||
buf.append(";Secure");
|
||||
buf.append("; Secure");
|
||||
}
|
||||
if (cookie.isHttpOnly()) {
|
||||
buf.append(";HttpOnly");
|
||||
buf.append("; HttpOnly");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue