Save query parameters in WebSessionServerRequestCache

Previously, URL query parameters were lost when saving a request
in WebSessionServerRequestCache. Now it is properly saved and
restored.
This commit is contained in:
Denis Washington 2019-01-15 13:56:21 +01:00 committed by Rob Winch
parent c0e66a9ba1
commit 3be11a22cd
2 changed files with 13 additions and 1 deletions

View File

@ -90,7 +90,9 @@ public class WebSessionServerRequestCache implements ServerRequestCache {
}
private static String pathInApplication(ServerHttpRequest request) {
return request.getPath().pathWithinApplication().value();
String path = request.getPath().pathWithinApplication().value();
String query = request.getURI().getRawQuery();
return path + (query != null ? "?" + query : "");
}
private static ServerWebExchangeMatcher createDefaultRequestMacher() {

View File

@ -44,6 +44,16 @@ public class WebSessionServerRequestCacheTests {
assertThat(saved).isEqualTo(exchange.getRequest().getURI());
}
@Test
public void saveRequestGetRequestWithQueryParamsWhenGetThenFound() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/").queryParam("key", "value").accept(MediaType.TEXT_HTML));
this.cache.saveRequest(exchange).block();
URI saved = this.cache.getRedirectUri(exchange).block();
assertThat(saved).isEqualTo(exchange.getRequest().getURI());
}
@Test
public void saveRequestGetRequestWhenFaviconThenNotFound() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/favicon.png").accept(MediaType.TEXT_HTML));