Skip to content

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

Open
@spencergibb

Description

@spencergibb

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions