refactor: use functional streams for host and path predicate accumulation#4128
Merged
ryanjbaxter merged 2 commits intospring-cloud:mainfrom Mar 30, 2026
Merged
Conversation
Signed-off-by: Yuri-Costa09 <yurircostawork@gmail.com>
… format code following codebase rules. Signed-off-by: Yuri-Costa09 <yurircostawork@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors GatewayRequestPredicates to build composite host/path predicates using Java Streams, and adds Javadoc to clarify usage of the host overloads.
Changes:
- Refactored
host(String... patterns)to combine multiple host predicates viaStream.reduce(RequestPredicate::or). - Refactored
path(String... patterns)to combine multiple path predicates viaStream.reduce(RequestPredicate::or). - Added Javadoc for
host(String pattern)andhost(String... patterns)to align with the documentation style of other predicates in the class.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Thank you for your time! @ryanjbaxter :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the way multiple host and path patterns are handled in
GatewayRequestPredicates. The main improvement is replacing manual loops with more concise and functional Java Stream API usage, making the code cleaner and easier to read.Changes
host(String... patterns)method to use Java Streams for combining multiple host predicates withor, replacing the previous manual loop.path(String... patterns)method to use Java Streams for combining multiple path predicates withor, replacing the previous manual loop.Documentation improvements:
host(String pattern)andhost(String... patterns)methods to clarify their purpose and usage. Following the convention of other existing methods.Motivation
This PR refactors the host predicate accumulation to use a functional style with Java Streams, resolving a legacy "TODO" and aligning the implementation with other predicates like path.
Key benefits:
Readability & Modernization: Replaces imperative for loops with declarative Streams, reducing cognitive load and removing manual index management ("magic numbers").
Immutability & Safety: Leverages the Streams API to ensure immutable operations during the predicate tree construction, which is a best practice in reactive environments like Spring Cloud Gateway.
Future-Proofing: While the current number of patterns is usually small, this functional approach allows for easier evolution (such as parallelization) without changing the core logic.
Documentation: Added Javadocs to the host methods to improve the developer experience for both users and future contributors, maintaining consistency across the RequestPredicates class.
All tests passed, Build Successful.