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

Support paths on Route URIs as syntactic sugar for the `SetPath` filter

Open
#3,293 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

There have been multiple requests and feedback regarding the ignoring of paths on Route URIs. Part of my hesitancy is how to support it across ALL means of configuring routes both reactive and MVC: config props, Java DSL and actuator.

I'm comfortable proposing it as syntactic sugar for the SetPath filter. There would be a mechanism to remove the path from the URI and insert a SetPath filter with that URI. There would be NO customization, at that point, break out to the original SetPath configuration.

The two routes in each of the following examples would be equivalent:

spring:
  cloud:
    gateway:
      routes:
      - id: set_path
        uri: http://example.com
        predicates:
        - Path=/foo/{segment}
        filters:
        - SetPath=/{segment}
      - id: set_path_uri
        uri: http://example.com/{segment}
        predicates:
        - Path=/foo/{segment}

reactive Java DSL

@Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
  return builder.routes()
      .route("setpath", p -> p.path("/foo/{segment}")
          .filters(f -> f.setPath("/{segment}"))
          .uri("http://example.com"))
      .route("setpathuri", p -> p.path("/foo/{segment}")
          .uri("http://example.com/{segment}"))
      .build();
}

MVC Java DSL

@Bean
public RouterFunction<ServerResponse> setPathRoute() {
  return route("setpath")
      .route(path("/foo/{segment}"), http("http://example.com"))
        .before(setPath("/{segment}"))
      .build().and(route()
        .route(path("/foo/{segment}"), http("http://example.com/{segment}"))
      .build());
}

/cc @joshlong

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

Start by tracing route URI handling across configuration properties, the reactive Java DSL, the MVC Java DSL, and actuator support. Compare each path-bearing URI with the equivalent SetPath examples in the issue; done means the path is removed from the URI and applied consistently as SetPath in all listed configuration paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.