简体   繁体   中英

How to stop spring-boot embedded-undertow from adding trailing slash

When i call the context root of my spring-boot application " localhost:8080/api/players ", which is mapped in a RestController method by the annotation @GetMapping(path= {"/",""}), undertow alway redirect (httpstatus: 307 Temporary redirect) to " localhost:8080/api/players/ " adding trailing slash at the end.

My application context-root is indeed /api/players as defined in spring-boot application.properties file ( server.servlet.context-path=/api/players )

I've tried with embedded-tomcat and it works correctly by setting the property server.tomcat.redirect-context-root=false

There is a way to configure undertow to act like tomcat?

Peering into the sourcecode for undertow a bit, it looks like the relevant code is here in ServletInitialHandler.java , which will issue a 307 redirect status code in the case that the request is an upgrade request... unless the request is an HTTP 2 upgrade request. This doesn't seem to be configurable by the server, although there is some attempt to avoid the redirect based on what the client does.

It's probably worthwhile to look at your HTTP requests, understand better if your HTTP client is actually making an upgrade request, and then consider either accepting this fact, or changing the client to make a different kind of request (possibly by making it send the HTTP2 upgrade request header).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM