spring-cloud / spring-cloud/spring-cloud-gateway

Clarify or() behavior

Open
#2,684 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Is your feature request related to a problem? Please describe.

When using the fluent Java API the behavior of or() is not well documented when combined with and().

In these examples route-1 matches while route-2 does not.

.route("route-1", r -> r.predicate(swe -> false)
        .and().predicate(swe -> true)
        .or().predicate(swe -> true)
        .and().predicate(swe -> true)
        .and().predicate(swe -> true)
        .uri(...)
.route("route-2", r -> r.predicate(swe -> true)
        .and().predicate(swe -> true)
        .or().predicate(swe -> true)
        .and().predicate(swe -> true)
        .and().predicate(swe -> false)
        .uri(...)

I am guessing that the precedence is as follows:

((((false && true) || true) && true) && true) // => true
((((true && true) || true) && true) && false) // => false

Describe the solution you'd like

or() is only mentioned once in the documentation (unless I missed another section talking about it).

IMHO that precedence should be clearly documented since it might not be obvious for everyone and might cause configuration issues.

Describe alternatives you've considered

Is there any plan to add nested boolean expressions in the API? Something like:

.route("route", r -> r
        .nested(r.host(...).or().header(...))
        .and()
        .nested(r.predicate(...).or().predicate(...))
        .uri(...)

It might be less readable but would offer a more powerful API.

Additional context

What I originally wanted to do is check the hostname in either Host or X-ORIGINAL-HOST, something HostRoutePredicateFactory cannot do right now.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the Fluent Java Routes API section at the linked documentation page and review the existing mention of or(). Use the two supplied route examples to clarify how or() combines with and(), and define completion as updated documentation that explains the behavior; treat nested expressions as a separate scope question.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.