Skip to content

Fix cookie parsing in MockMvcClientHttpRequestFactory - #37685

Open
noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:fix-mockmvc-cookie-parsing
Open

noojung wants to merge 1 commit into
spring-projects:mainfrom
noojung:fix-mockmvc-cookie-parsing

Conversation

@noojung

@noojung noojung commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

When using RestTestClient with MockMvc, multiple cookies are incorrectly parsed as a single cookie.

For example, sending Cookie: foo=bar; baz=qux to the following controller results in request.getCookies() returning only one cookie named foo with the value bar; baz=qux, instead of two separate cookies:

@GetMapping(path = "/cookies")
public String cookies(HttpServletRequest request) { 
	Cookie[] cookies = request.getCookies();
	
	// ...
}

This happens because MockMvcClientHttpRequestFactory splits Cookie headers on commas(,).

This PR fixes the issue by splitting Cookie headers on semicolons(;) instead of commas(,), ensuring that each cookie is parsed separately.

Cookie headers were split on commas, causing multiple cookies to be
parsed as a single cookie. Split on semicolons to preserve each cookie's
name and value.

Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants