spring-cloud / spring-cloud/spring-cloud-gateway
stripPrefix filter always add a "/" in path
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
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/");
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the proposed cases in BeforeFilterFunctionsTests and trace the stripPrefix and prefixPath entry points. Confirm that stripping /get yields an empty path while stripping /get/ yields "/", then run the relevant gateway tests and ensure both expected paths pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100