Skip to content
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

Simplify applying a strategy to requests from WebTestClient and WebTestClient [SPR-15691] #20250

spring-issuemaster opened this issue Jun 22, 2017 · 2 comments


None yet
2 participants
Copy link

commented Jun 22, 2017

Rob Winch opened SPR-15691 and commented


With the changes from #20216 modifying a request with a strategy (i.e. ExchangeFilterFunction) becomes 3 statements instead of a single one. For example, we use to have:


now the code is


It would be ideal to make this a single statement again.

Solution Ideas

Combining Methods

One idea would be to provide a single method that accepts an ExchangeFilterFunction and invokes all three methods.

   // shortcut for mutate, filter, build

ClientRequest attributes

Another (improved) approach would be to allow ClientRequest to have some concept of attributes. Perhaps something like:

   .with( requestAttrs -> { .. })

This would allow the ExchangeFilterFunction to leverage the requestAttrs and thus remain stateless.

This approach improves usability in regards to if an ExchangeFilterFunction needed some values that were always reused. Currently (and in the past) we would need to do something like:

  .filter(oauth(someBeanThatIsConstant, a1, b1,...))

  .filter(oauth(someBeanThatIsConstant, a2, b2,...))

You can see that this is a burden on the user to have to provide someBeanThatIsConstant for every request. With the above approach the someBeanThatIsConstant can be injected into an ExchangeFilterFunction that is global and the requestAttrs would provide values that change.

webClient = ...

  .with( requestAttrs -> { ... } )

  // here oauth is just a static method provided by Spring Security that creates
  // a consumer that does the same thing as above
  .with( oauth(a1,a2) )

This approach also means we can make additional requests in the ExchangeFilterFunction using the ExchangeFunction without worrying about another ExchangeFilterFunction adding something that is isn't desirable to the request. For example, currently if a user makes an HTTP basic request and we want to do something inside another ExhangeFunction that makes a request, the ExchangeFunction passed in would automatically populate HTTP Basic on the new request which is not necessarily desirable.

With ClientRequest attributes the attributes would not be populated on this additional request so the ExchangeFunction would not add the basic auth headers.

Affects: 5.0 RC3

Issue Links:

  • #20216 Ordering of WebClient.filter(s)

Referenced from: commits 74b4c02


This comment has been minimized.

Copy link
Collaborator Author

commented Jul 5, 2017

Arjen Poutsma commented

This is now in master, see 74b4c02

As part of this commit, I've also updated the basic authentication filter so that it can take the username/password from attributes, as well as use String parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.