-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Use request.requestPath().value() to populate path error attribute with WebFlux #37269
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
Comments
The option to not include the message is for security purposes. That doesn't apply so much to the path. If the gateway set the If you really want to remove the |
@wilkinsona Thanks for response 👍 I've just generated a new project with webflux, and tried such a test: @SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
properties = [
"server.port=8080",
"server.forward-headers-strategy=native"
]
)
class HeaderTestApplicationTests {
private val client = WebTestClient
.bindToServer()
.baseUrl("http://localhost:8080")
.build()
@Test
fun `should use X-Forwarded-Prefix path in error`() {
val response = client.get()
.uri("/bar")
.header("X-Forwarded-Prefix", "/foo")
.exchange()
response.expectBody()
.jsonPath("path")
.isEqualTo("/foo")
}
} Unfortunately, it fails, |
Have you tried with |
Yup, I did, it is the same: @Test
fun `should use X-Forwarded-Prefix path in error`() {
assertEquals(serverProps.forwardHeadersStrategy, FRAMEWORK)
val response = client.get()
.uri("/bar")
.header("X-Forwarded-Prefix", "/foo")
.exchange()
response.expectBody()
.jsonPath("path")
.isEqualTo("/foo") // reports failure, because it is equal to /bar
} |
To my surprise, @Bean
ErrorAttributes customErrorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
Map<String, Object> attributes = super.getErrorAttributes(request, options);
attributes.put("path", request.requestPath().value());
return attributes;
}
};
} In your test, this produces a path of I'd like to discuss this with the team as it feels like this would be better default behaviour. However, I may be overlooking something. |
Oh, yeah, you are right, the path should be Thanks for your suggestion, we created a similar custom error attributes bean to handle this case 🙂 |
We discussed this today on our team call and we're going to look at what happens with the Servlet version so that we can align. We also think adding an exclude option is worthwhile. |
I was playing around with that on the Servlet stack. My findings:
Here's the project: sb-37269.zip |
I've created a ticket for the path inclusion configuration: #38619 |
I think this has been addressed by spring-projects/spring-framework#30828 |
Thanks for the pointer. Just tested with |
Now that this is fixed on the servlet stack, I think we should change our errorAttributes.put("path", request.requestPath().value()); WDYT? |
Makes sense to me. I'm not 100% sure on the timing of the change though. It feels like a bug so 3.1.x is tempting but I wonder if there's a chance it'll break someone in which case 3.3 would be better with the option to provide a custom |
We discussed this today and decided to address this in 3.3 as the change may not be 100% backwards compatible. In the meantime, those that want the proposed behavior today can use a custom |
Hi, let's say that we have a simple architecture with ingress gateway in front that handles all incoming requests, and orders service that is responsible for handling incoming requests about orders domain.
When such request is send to the ingress gateway:
GET /api/orders
, it should be rerouted to different path, let's sayGET /orders
. In this case, when orders service returns an error, for example 400 Bad Request, it would contain error details, like:If we take a closer look at
path
property, it contains wrongpath
from caller perspective. I wonder if we should add an option, similar to server.error.include-message config property to excludepath
from error attributes.What do you think?
The text was updated successfully, but these errors were encountered: