-
Notifications
You must be signed in to change notification settings - Fork 38.5k
MockHttpServletRequest setCookies should join cookies to single Cookie header #23029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for raising the issue. I believe your interpretation of the RFC is correct: In addition, we should also add Javadoc to that method. Related issues: |
Tentatively slated for 5.2 M3 as an enhancement |
Updated test case using AssertJ so that it is compatible with @Test
public void cookiesRegressionIssue() {
MockHttpServletRequest request = new MockHttpServletRequest();
Cookie cookie1 = new Cookie("foo", "bar");
Cookie cookie2 = new Cookie("baz", "qux");
request.setCookies(cookie1, cookie2);
Cookie[] cookies = request.getCookies();
assertAll("Cookies>Headers conversion should work", //
() -> assertThat(cookies.length).isEqualTo(2), //
() -> assertThat(cookies[0].getName()).isEqualTo("foo"),
() -> assertThat(cookies[0].getValue()).isEqualTo("bar"),
() -> assertThat(cookies[1].getName()).isEqualTo("baz"),
() -> assertThat(cookies[1].getValue()).isEqualTo("qux"),
() -> assertThat(request.getHeader("Cookie")).isEqualTo("foo=bar; baz=qux"),
() -> assertThat(Collections.list(request.getHeaders("Cookie"))).size().isEqualTo(1));
} |
What do Tomcat or Jetty do for comparison's sake? If there is any consensus there then I would align with that. |
I glanced at their code bases, and it appears that they both accept one or more But since this issue is about @chas678, do you have a particular use case that requires a single |
@sbrannen - Use case was I was having to extract and manipulate a cookie value. The code was using getCookies, but the test was using the header and failing as was checking/expocting multiple values after manipulation. It took me a while to work out there were multiple Cookie header entries and I was a little surprised. I now loop over the getCookies array in test also so not a blocker. |
OK. Thanks for the feedback. |
Superseded by #23074 |
Version
spring-test-5.1.6.RELEASE
Overview
setCookies
on aMockHttpServletRequest
sets multiple "Cookie" Headers. It should concatenate the cookie name/value pairs into a single "Cookie" header string joined with delimiter"; "
.MockHttpServletRequest
setCookies
javadoc has little detail on what behavior a user should expect. If the behavior deviates from rfc6265 syntax by design then could the documentation be amended to reflect that?Test case exposing defect
The text was updated successfully, but these errors were encountered: