spring-data-rest changed basePath behavior
Closed this issue · 11 comments
While we updated our microservices from spring-boot 2.0.5.RELEASE
to 2.1.0.RELEASE
and therefore to spring-cloud version Greenwich.M1
we noticed following change in spring-data-rest
Before the upgrade the basePath of the links within the REST response corresponded with the basePath of our gateway running on 8080
, e.g.
{
...
"_links": {
"self": {
"href": "http://localhost:8080/person/123"
}
}
}
After the upgrade the basePath corresponds with the host name of the server the service is running on, e.g.
{
...
"_links": {
"self": {
"href": "http://devsXXX:8081/person/123"
}
}
}
I don't suspect that this is an expected change
Thanks for the report, but I don't think we'll be able to make any progress without some more information. When an application is running behind a gateway or proxy, the headers that are added by the gateway or proxy influence the URLs that will be returned by the application. Without knowing what headers are being sent, it's impossible to diagnose why the application's behaviour has changed.
If you'd like us to spend some time trying to help you, can you please take the time to provide a complete, minimal example that reproduces the problem. That could be both an application and detailed instructions for setting up the gateway or proxy in front of it, or, ideally, just the application along with details of curl requests that can be sent to the application that mimic the behaviour of the proxy or gateway.
Thanks @wilkinsona Im working on a minimal sample application to mimic the behavior
@wilkinsona
Please find my sample repo here
2.1.0
https://github.com/gabac/spring-data-rest-bug/tree/spring-boot-2.1.0
2.0.5
https://github.com/gabac/spring-data-rest-bug/tree/spring-boot-2.0.5
Thanks for the sample. The change in behaviour is due to this change in Spring Framework 5.1. You can enable centralised handling of Forward-
headers in Spring Boot by setting server.use-forward-headers=true
.
I've updated Boot's release notes with a link to Framework 5.1's upgrade guide.
After setting the forward headers I don't see any change in behaviour.
See commit: gabac/spring-data-rest-bug@212a215
I had to create a ForwardedHeaderFilter
Bean to get it to work
There's no need to enable the forward headers in the gateway as it's not having requests forwarded to it. It works for me based on gabac/spring-data-rest-bug@212a215 and this diff:
diff --git a/demo-app/gateway/src/main/resources/application.yml b/demo-app/gateway/src/main/resources/application.yml
index 67820f9..cc9d3fa 100644
--- a/demo-app/gateway/src/main/resources/application.yml
+++ b/demo-app/gateway/src/main/resources/application.yml
@@ -3,7 +3,6 @@ spring:
name: gateway
server:
port: 8080
- use-forward-headers: true
zuul:
routes:
person-service:
It looks like it's working to me as it's coming back with the correct port (8080 vs 8081).
localhost
vs 10.242.134.66
will depend on the configuration of your network stack, what network interface the service is bound to, etc.
This is really beyond the scope of this issue now as there's nothing to change in Spring Boot. If you'd like to follow up on network stack configuration, controlling the address to which a service binds, etc, please do so on Gitter or Stack Overflow.
Ah sorry was only looking for localhost
vs 10.242.134.66
; yes the ports are corect now.
Interestingly with a ForwardedHeaderFilter
, localhost
instead 10.242.134.66
of is returned.