-
Notifications
You must be signed in to change notification settings - Fork 38.5k
WebClient's ResponseSpec should provide access to response headers #22368
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
Caching the response isn't an option, and it wouldn't cover the Flux case either. Having to break the fluent chain of calls with a @poutsma we considered |
At some point, we moved the But we could expose the response headers in
I am not sure about the names yet, but the idea should be clear: you get access to both headers and body mono/flux in a function. We might even consider exposing the status code as well. This would allow you to do the following:
Thoughts? |
@poutsma that makes sense to me and would cover my use case perfectly. The only thing that it might not cover is easy access to cookies. I suppose one could always parse cookies from the headers, but |
Despite my earlier comment, I decided to go with duplicating |
Affects: 5.1.4
This in an enhancement request for
WebClient
.Currently there are two ways to process the response with
WebClient
:WebClient#exchange()
gives full access to theClientResponse
(including the HTTP response headers), but it requires one to handle erroneous HTTP status codes manually.WebClient#retrieve()
simplifies error handling, but prevents access toClientResponse
.I find myself using
retrieve()
almost exclusively, but sometimes I have to resort toexchange()
(and doing my own error handling) due to the limitation described above.It would be really nice for
WebClient#retrieve()
to provide access toClientResponse
(or at least the HTTP response headers) while still taking care of the bad status code handling.An example use case of this is extracting a value from a HTTP header or a cookie in addition to deserializing the body to an object.
A potential implementation of this could be to add
Mono<ClientResponse> clientResponse();
toWebClient.ResponseSpec
.DefaultResponseSpec
would call.cache()
on theresponseMono
in the constructor, and return that from the newclientResponse()
method.That would allow one to write something like:
An alternative solution could be to simply make
DefaultResponseSpec
public
, so that one could do this manually:The text was updated successfully, but these errors were encountered: