You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MockHttpServletRequest setCookies should join cookies to single Cookie header #23029
setCookies on a MockHttpServletRequest sets multiple "Cookie" Headers. It should concatenate the cookie name/value pairs into a single "Cookie" header string joined with delimiter "; ".
MockHttpServletRequestsetCookies 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?
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 Cookie headers for incoming requests.
But since this issue is about MockHttpServletRequest, I suppose we'd be better off investigating what browsers or clients actually send to servers.
@chas678, do you have a particular use case that requires a single Cookie header in the request? In other words, is there a reason you cannot use javax.servlet.http.HttpServletRequest.getCookies() which abstracts over the actual headers present?
@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.
Activity
sbrannen commentedon May 24, 2019
Thanks for raising the issue.
I believe your interpretation of the RFC is correct:
MockHttpServletRequest.setCookies(...)should only create a singleCookieheader.In addition, we should also add Javadoc to that method.
Related issues:
sbrannen commentedon May 24, 2019
Tentatively slated for 5.2 M3 as an enhancement
sbrannen commentedon May 24, 2019
Updated test case using AssertJ so that it is compatible with
master.rstoyanchev commentedon May 24, 2019
What do Tomcat or Jetty do for comparison's sake? If there is any consensus there then I would align with that.
sbrannen commentedon May 26, 2019
I glanced at their code bases, and it appears that they both accept one or more
Cookieheaders for incoming requests.But since this issue is about
MockHttpServletRequest, I suppose we'd be better off investigating what browsers or clients actually send to servers.@chas678, do you have a particular use case that requires a single
Cookieheader in the request? In other words, is there a reason you cannot usejavax.servlet.http.HttpServletRequest.getCookies()which abstracts over the actual headers present?chas678 commentedon May 28, 2019
@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.
sbrannen commentedon May 28, 2019
OK. Thanks for the feedback.
rstoyanchev commentedon May 28, 2019
Right, and I think I misread the issue. It looks like a bug indeed. Here is for comparison Netty and Jetty clients which do create a single value.
sbrannen commentedon Jun 5, 2019
OK. I'll change it to a "bug", and I'll review the PR submitted in #23074.
sbrannen commentedon Jun 5, 2019
Superseded by #23074