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
/** * Global option to specify a header to be added to every request, * if the request does not already contain such a header. */BuilderdefaultHeader(Stringheader, String... values);
WebClient and RestClient have default[Header|Cookie|Request|..] that useful to set default value on request.
As you can see above code, defaultHeader value is set only when it's not contained in headers.
Question
/** * Provide a consumer to customize every request being built. * @param defaultRequest the consumer to use for modifying requests */BuilderdefaultRequest(Consumer<RequestHeadersSpec<?>> defaultRequest);
FYI, I found this issue while investigating #32028 😃
If this behavior of defaultRequest(..) is intended, feel free to close this issue~!
(I simply think that defaultRequest works similarly with defaultHeader, setting default value)
snicoll
changed the title
[Question] WebClient and RestClient's defaultRequest(..) behavior about setting default valuesWebClient and RestClient's defaultRequest(..) behavior about setting default values
Jan 18, 2024
Thanks for spotting this odd behavior, which is indeed not intentional. However, the fact remains that the current behavior has been present since 5.0, and changing it, to do effectively the opposite of what it is currently doing, can affect many users.
Fixing this issue is trivial—I have a fix locally—but that fix won't be merged until 6.2.
even though this is a bug—it will not be backported to the 6.1, 6.0, or 5.3 branches, as it fixing it will break backward compatibility.
Aha I understood! I agree with your opinion. I just wondered it's bug or intended behavior.
Anyway I'm glad to found this trivial bug, and please share if there's something I can help~ thanks! 🙇
rstoyanchev
changed the title
WebClient and RestClient's defaultRequest(..) behavior about setting default valuesWebClient and RestClient's defaultRequest(..) is not invoked early enough
Jan 25, 2024
bclozel
changed the title
WebClient and RestClient's defaultRequest(..) is not invoked early enough
WebClient and RestClient's defaultRequest(..) is not invoked early enough
Feb 14, 2024
Background
WebClient
andRestClient
havedefault[Header|Cookie|Request|..]
that useful to setdefault value
on request.spring-framework/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java
Lines 502 to 508 in 899de4f
As you can see above code,
defaultHeader
value is set only when it's not contained in headers.Question
spring-framework/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java
Lines 481 to 484 in 899de4f
But on
defaultRequest(..)
, it can override request's values unlikedefaultHeader
cause it's called on every request being built.Reproduce
I think
defaultRequest(spec -> spec.accept(MEDIA_TYPE))
will override all media types that set byaccept(..)
on this request.Q. is above behavior of
defaultRequest(..)
is intended? thanks!The text was updated successfully, but these errors were encountered: