Skip to content

MockHttpServletResponse addHeader does not allow Comment part with Set-Cookie header #28730

Closed
@charlesk40

Description

@charlesk40

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

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions