mirror of https://github.com/halo-dev/halo
Add support for rewriting URL with trailing slash (#7559)
parent
8fd23e2c68
commit
7d560186e8
|
@ -25,6 +25,7 @@ import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
|||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.web.filter.reactive.ServerWebExchangeContextFilter;
|
||||
import org.springframework.web.filter.reactive.UrlHandlerFilter;
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistration;
|
||||
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
|
||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||
|
@ -267,4 +268,11 @@ public class WebFluxConfig implements WebFluxConfigurer {
|
|||
return new ServerWebExchangeContextFilter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
UrlHandlerFilter urlHandlerFilter() {
|
||||
return UrlHandlerFilter
|
||||
.trailingSlashHandler("/**").mutateRequest()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ import run.halo.app.extension.Metadata;
|
|||
SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@Import({
|
||||
WebFluxConfigTest.WebSocketSupportTest.TestWebSocketConfiguration.class,
|
||||
WebFluxConfigTest.ServerWebExchangeContextFilterTest.TestConfig.class
|
||||
WebFluxConfigTest.ServerWebExchangeContextFilterTest.TestConfig.class,
|
||||
WebFluxConfigTest.UrlHandlerFilterTest.TestConfig.class
|
||||
})
|
||||
@AutoConfigureWebTestClient
|
||||
class WebFluxConfigTest {
|
||||
|
@ -206,4 +207,29 @@ class WebFluxConfigTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
class UrlHandlerFilterTest {
|
||||
|
||||
@TestConfiguration
|
||||
static class TestConfig {
|
||||
|
||||
@Bean
|
||||
RouterFunction<ServerResponse> urlHandlerFilterTestRoute() {
|
||||
return RouterFunctions.route()
|
||||
.GET("/fake", request -> ServerResponse.ok().bodyValue("ok"))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHandleUrlWithTrailingSlash() {
|
||||
webClient.get().uri("/fake/")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody(String.class).isEqualTo("ok");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue