Affects: 5.3.3
The Javadoc for ServerHttpRequest.getPath() reads:
Returns a structured representation of the request path including the context path + path within application portions, path segments with encoded and decoded values, and path parameters.
However, getPath().toString() actually results in the path only up to (but excluding) the first "?". Any query parameters that were part of the original URI are not included, contrary to what the Javadoc claims.
For example, this Kotlin/JUnit5 test
@Test
fun getPathShouldContainParams() {
val exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://test.com/items?id=5"))
assertThat(exchange.request.path).isEqualTo("/items?id=5")
}
fails with this message:
org.opentest4j.AssertionFailedError: expected:<["/items?id=5"]> but was:<[/items]>
Expected :/items?id=5
Actual :/items
When debugging into the test, I could see that the returned RequestPath object doesn't contain any info about the parameters.
I first noticed this in production, i.e. this als happens with real requests, not just with mocked ones.
Expected behavior: ServerHttpRequest.getPath() returns an object that knows about the parameters, and returns them as part of its toString().
Comment From: rstoyanchev
Query parameters are available via request.getQueryParams()
. The Javadoc for getPath()
talks about path parameters which are part of the path (e.g. "/foo;a=b"
) and not the same as query parameters.
Comment From: fblampe
I see. Thanks for clearing that up for me.
I still think that's quite confusing though, since the Javadoc doesn't contain that clarification... :(
Comment From: rstoyanchev
I mean it does say "path parameters" rather than "query parameters". Can you suggest how would you like that text to change, I'll be happy to consider it?
Comment From: fblampe
Some options I can think of would be (additions in italics here; but can be regular text in Javadoc):
Returns a structured representation of the request path including the context path + path within application portions, path segments with encoded and decoded values, and path parameters. Query parameters are not included.
Returns a structured representation of the request path including the context path + path within application portions, path segments with encoded and decoded values, and path parameters. Note: Query parameters are not included.
Returns a structured representation of the request path including the context path + path within application portions, path segments with encoded and decoded values, and path parameters (but not query parameters).
Comment From: rstoyanchev
Okay I see. I'll add something that mentions there is a separate method for access to the query and that the path is just the path.
Comment From: fblampe
I like it, thanks!