-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Revise cookies support with Apache HTTP Components in WebClient and WebTestClient #33822
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
Furthermore the WebTestClient API /**
* Manipulate this request's cookies with the given consumer. The
* map provided to the consumer is "live", so that the consumer can be used to
* {@linkplain MultiValueMap#set(Object, Object) overwrite} existing header values,
* {@linkplain MultiValueMap#remove(Object) remove} values, or use any of the other
* {@link MultiValueMap} methods.
* @param cookiesConsumer a function that consumes the cookies map
* @return this builder
*/
S cookies(Consumer<MultiValueMap<String, String>> cookiesConsumer); |
You raise a good point that is more general to our Apache HttpClient support for WebClient an WebTestClient. For client side cookies we only aim to facilitate setting the request, and reading the response, but not to store them especially across requests or paths and domains. In that sense, I'm not sure that our use of the
For comparison, we recently added support for cookies to |
Thanks @rstoyanchev ! This is great stuff.
I'd note that without the user explicitly disabling cookie management in the underlying HttpClient (see HttpClientBuilder#disableCookieManagement) that the cookiestore is still used by default and therefore cookies received in previous requests may be sent in a new one without explicitly adding them. Should WebClient enforce disabling cookie management, or log a warning if cookie management is enabled? I left a couple of comments on the implementation also; |
Re-opening to address the feedback. |
About the CookieStore, I don't think we need to get in the way of someone wanting to use that vs passing them on every request. I see, however, our HttpComponentsClientHttpConnector sets up a BasicCookieStore by default, and that should not longer be necessary. I will remove it. I also responded on the commit comments. |
Uh oh!
There was an error while loading. Please reload this page.
Steps to reproduce
Expected bevaviour:
only cookies which were returned from a 'Set-Cookie' header in the HTTP response are found when calling
org.springframework.test.web.reactive.server.ExchangeResult#getResponseCookies
.Actual behaviour:
cookies set on the request are also present in getResponseCookies, with spurious 'Path' metadata, even though no such cookies were returned from the server.
It seems like the problem is in
org.springframework.http.client.reactive.HttpComponentsClientHttpRequest#applyCookies
: this is creating entries in the cookieStore with 'path' and 'domain' metadata set to whatever we are currently requesting.Then this same cookieStore then used to store response cookies; see
org.springframework.http.client.reactive.HttpComponentsClientHttpResponse#getCookies
:I can prepare a simple example project shortly.
The text was updated successfully, but these errors were encountered: