spring-cloud-gateway
spring-cloud-gateway copied to clipboard
stripPrefix filter always add a "/" in path
Describe the bug stripPrefix filter actually always give "/" while sometime it should be ""
I don't know if this is intended or if it's a bug, in one of my project I had to change the stripPrefix filter in order to call correct URL (without the ending /)
Sample
Add theses tests in BeforeFilterFunctionsTests
The fail with http://localhost/get url, with Strip Prefix to 1 and prefixPath to "/prefix" should call /prefix url, but instead call /prefix/ that is not the same URL
@Test
void stripPrefixAndPrefixPathFail() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders
.get("http://localhost/get").buildRequest(null);
ServerRequest request = ServerRequest.create(servletRequest,
Collections.emptyList());
// StripPrefix 1 should give "" as the path
ServerRequest modified = BeforeFilterFunctions.stripPrefix(1)
.andThen(BeforeFilterFunctions.prefixPath("/prefix")).apply(request);
// PrefixPath should give "/prefix" + "" as the path
// ACTUALLY gives "/prefix/" as the path, this test FAILS
assertThat(modified.uri().getRawPath()).isEqualTo("/prefix");
}
@Test
void stripPrefixAndPrefixPathSuccess() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders
.get("http://localhost/get/").buildRequest(null);
ServerRequest request = ServerRequest.create(servletRequest,
Collections.emptyList());
// StripPrefix 1 should give "/" as the path
ServerRequest modified = BeforeFilterFunctions.stripPrefix(1)
.andThen(BeforeFilterFunctions.prefixPath("/prefix")).apply(request);
// PrefixPath should give "/prefix" + "/" as the path
// This test PASS
assertThat(modified.uri().getRawPath()).isEqualTo("/prefix/");
}