-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring Cloud Gateway doesn't add X-Forwarded-Prefix header #314
Comments
Did a bit more investigation comparing headers added by zuul and S-C-G and it seems the difference is the X-Forwarded-Prefix header isn't being added |
I've created a minimal app for another gateway issue with chains of proxies that I'll be opening but it also shows this issue To reproduce, Don't know if this is an enhancement or needs documenting as unsupported but I feel Spring projects should be consistent in support for headers especially in simple cases like the If considered a valid bug or enhancement then I can look at submitting a PR for StripPrefix at least. |
I am also hitting this in Kubernetes (on AWS). I saw the same behaviour with nginx ingress before adding the annotation 'nginx.ingress.kubernetes.io/x-forwarded-prefix: "true"'. I wonder if the problem is just that XForwardedHeadersFilter doesn't included X-Forwarded-Prefix. I am trying to find out. (I notice from RobMaskell/gatewayissues that @RobMaskell was able to add a filter with "- AddRequestHeader=x-forwarded-prefix, /api" but I am using discovery locator so don't have a fixed path I can use.) |
@ryandawsonuk I couldn't find any x-forwarded-prefix related code in the x-forwarded filter so I came to the conclusion that it was unsupported for now |
There is a header called X-Original-URI that contains the path with the prefix in front. From this it is possible to extract the prefix. I tried overriding the XForwardedHeadersFilter class and found that it did then set the prefix and the links in the hateoas are then correct. |
I don't remember seeing that header in my case so maybe that will just work for you and not be a generic solution? |
Might be that it's an nginx thing. @RobMaskell Were you getting to the gateway via an ingress? |
@ryandawsonuk an Ingress yes but a garden variety GCP HTTP LB Ingress |
I have working zuul config and wanted to convert it to spring cloud gateway but I'm hitting a problem with the spring data rest / hateos response from my back-end api.
I have my gateway at
http://localhost:8888
and access the api withhttp://localhost:8888/api/foo
, the backend api server is athttp://localhost:7777
The problem is that the /api is missing from the hateoas generated URIs in the response coming back.
The zuul config I'm replicating is as follows
application.properties
The config for spring cloud gateway is as follows
application.properties
java api routes config
I've tried with and without the
x-forwarded
properties and it's the same withsetPath
andstripPrefix
and I'm out of ideas now.The text was updated successfully, but these errors were encountered: