Skip to content

Webflux base path does not work with Path predicates #1759

@anjuna

Description

@anjuna

Describe the bug

When setting a spring.webflux.base-path property all routes using Path predicates return 404 results

Sample

application.name: demo
server.port: 8080

spring.webflux.base-path: /myapp

spring.cloud.gateway:
  routes:
    - id: google-route
      uri: https://www.google.com/
      predicates:
        - Path=/api/**
      filters:
        - StripPrefix=1

Expected: Visit localhost:8080/myapp/api to see the google homepage (albeit stripped down).
Actual: 404

After digging a bit, I think this is because the PathRoutePredicateFactory uses the URI getRawPath.

Instead it could use a ServerHttpRequest's RequestPath then call pathWithinApplication, which is already set up correctly via the ContextPathCompositeHandler.

It is this ContextPathCompositeHandler which rejects the request earlier if you visit just localhost:8080/api, so the base-path property seems to be broken either way.

Is this change sensible? Or is there a separate feature which allows this functionality?

Thanks for your time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions