I'm using the following dependency for using MockHttpServletResponse for unit tests.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>6.0.0-M4</version>
<scope>test</scope>
</dependency>
Please see below test case where it shows that addHeader/getHeader methods from MockHttpServletResponse object do not return the same value; particularly the Comment part is stripped out.
I tried adding the same in Jetty container, and Jetty does not seem to strip the comment part. Also note that other header names like Set-CookieTest preserve the Comment part which seems to indicate that it only strips when encountering the Set-Cookie header name.
@Test
void addHeader() throws Exception {
MockHttpServletResponse servletResponse = new MockHttpServletResponse();
servletResponse.addHeader("Set-Cookie", "NOT_SAFE=;Domain=mydomain.com;Comment=COOKIECLEANER;Path=/;Expires=Thu, 01 Jan 1970 00:00:00 GMT");
System.out.println("MockHttpServletResponse: " + servletResponse.getHeader("Set-Cookie"));
}
Output:
MockHttpServletResponse: NOT_SAFE=; Path=/; Domain=mydomain.com; Expires=Thu, 1 Jan 1970 00:00:00 GMT
Comment From: sbrannen
That's correct.
Currently, MockHttpServletResponse.getCookieHeader(Cookie) does not include the value from jakarta.servlet.http.Cookie.getComment().
The counterpart to this issue is that MockCookie.parse(String) does not parse the Comment attribute.
So we have to fix it on both sides.
Comment From: sbrannen
This has been addressed for 5.3.22 and 6.0 M5 in 9ea45697ac5f99bd8f62a8391bdec4bbe35efab1.
Comment From: charlesk40
Great. Thank you!