XForwardPrefixPathAdjuster when having multiple proxys
See original GitHub issueHi i’m currently using v2.9.2 on my services.
I have a microservice environment, where all services are behind a Spring Cloud Gateway API proxy. Additional to this, the whole system is running on a Kubernetes cluster with a Traefik Ingress controller in place. So Traefik and Spring Cloud Gateway act as reverse proxies until the request eventually reaches the service in the backend. There, Swagger2 is running and provides the API docs.
Unfortunately it generates the field basePath
wrong, because the header contains a comma separated list of stripped prefixes for every proxy hop: /api,/my-service
.
The logic in XForwardPrefixPathAdjuster
only uses the value in this header as a whole, but should in my opinion merge all stripped prefixes again (i.e. just remove commas) to generate the base-path for use in the browser UI.
What do you think? Am i on the right path?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (2 by maintainers)
I have the same problem. In my gateway project the source like this.
the url is right.
but request url is not right.

I also encountered the same problem.swagger’s basePath is affected by x-forwarded-prefix in HTTP request header.The spring cloud gateway will automatically add x-forwarded-prefix when forwarding the request.This is the cause of the problem. So I disabled auto-add x-forwarded-prefix through the
spring.cloud.gateway.x-forwarded.prefix-enabled=false
configuration.Then added the correctx-forwarded-prefix
through the- AddRequestHeader=X-Forwarded-Prefix, /api/my-service
configuration. This solved my problem, but I don’t know if there’s a better way.