简体   繁体   English

如何阻止spring-boot Embedded-undertw添加尾部斜杠

[英]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. 当我将我的spring-boot应用程序的上下文根称为“ localhost:8080 / api / players ”时,该上下文根由在RestController方法中通过注解@GetMapping(path = {“ /”,“”})映射,始终始终重定向(httpstatus:307临时重定向)到“ localhost:8080 / api / players / ”,并在末尾添加斜杠。

My application context-root is indeed /api/players as defined in spring-boot application.properties file ( server.servlet.context-path=/api/players ) 我的应用程序上下文根目录确实是/ api / players,如春季启动的application.properties文件( 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 我已经尝试过Embedded-tomcat,并且通过设置属性server.tomcat.redirect-context-root = false可以正常工作

There is a way to configure undertow to act like tomcat? 有没有一种方法可以将underwow配置为像雄猫一样?

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. ServletInitialHandler.java一下ServletInitialHandler.java的源代码,看起来相关代码在ServletInitialHandler.java ,在请求是升级请求的情况下,它将发出307重定向状态代码...除非请求是HTTP 2升级要求。 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). 查看您的HTTP请求,了解您的HTTP客户端是否实际发出了升级请求,然后考虑接受此事实,或者考虑更改客户端以发出不同类型的请求(可能通过使其发送HTTP2),可能是值得的升级请求标头)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring-boot 休息 api。 截断尾部斜杠 - Spring-boot rest api. Truncate trailing slash 在 spring boot 嵌入式 undertow 上将 http 重定向到 https - Redirect http to https on spring boot embedded undertow 如何使用 Undertow 在 Spring-boot 中取消未完成的、长时间运行的请求? - How to cancel unfinished, long-running requests in Spring-boot with Undertow? 你如何在 spring boot 3 中忽略 webflux 中的尾部斜杠? - How do you ignore trailing slash in webflux in spring boot 3? 带有嵌入式 Tomcat 的 Spring Boot 应用程序在请求 /contextPath 时不重定向到 https 而不使用尾部斜杠 - Spring Boot application with embedded Tomcat behind reverse proxy not redirecting to https when asking for /contextPath without trailing slash 如何避免使用Spring-Boot下载嵌入式MongoDb - How to avoid embedded MongoDb download with Spring-Boot 如何在Eclipse中运行带有瓷砖的spring-boot嵌入式tomcat? - How to run spring-boot embedded tomcat with tiles in eclipse? Spring Boot 应用程序中未插入尾部斜杠 - Trailing slash is not inserted in Spring Boot application 如何在Spring-Boot中启动(并最终停止)守护程序线程? - How to start (and eventually stop) a daemon thread in Spring-Boot? Spring-Boot无法启动嵌入式Tomcat - Spring-Boot not able to start embedded Tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM