在SpringBoot 2.1中确定传入RequestEntity的HTTP版本
我试图从Spring中传入的HTTP请求中获取HTTP版本(特别是SpringBoot2.1.4)。表示RFC2616中“请求行”中定义为“HTTP版本”的在SpringBoot 2.1中确定传入RequestEntity的HTTP版本,spring,http,httprequest,Spring,Http,Httprequest,我试图从Spring中传入的HTTP请求中获取HTTP版本(特别是SpringBoot2.1.4)。表示RFC2616中“请求行”中定义为“HTTP版本”的HTTP 1.1部分:。 Spring的RequestEntity似乎有各种各样的功能来获取url、路径、头等等,但不是这个。官方文件也帮不上忙 考虑以下代码: @RestController @RequestMapping("/") public class MyController { @GetMapping("/") @
HTTP 1.1
部分:。
Spring的RequestEntity
似乎有各种各样的功能来获取url、路径、头等等,但不是这个。官方文件也帮不上忙
考虑以下代码:
@RestController
@RequestMapping("/")
public class MyController
{
@GetMapping("/")
@ResponseBody
public ResponseEntity<String> getSomething(RequestEntity requestEntity)
{
// access HTTP Version number of incoming RequestEntity ***HERE***
不过,似乎没有办法从RequestEntity中删除HTTP版本号
但是有吗?RequestEntity是请求的高级表示形式,允许您方便地以对象形式访问负载。您所追求的是请求的一个级别低得多的属性,通常REST端点不必为它自己操心 您可以注入HttpServletRequest实例,这样您就可以访问该协议
@GetMapping("/")
@ResponseBody
public ResponseEntity<String> getSomething(RequestEntity requestEntity,
HttpServletRequest request) {
log.info("HTTP protocol: " + request.getProtocol());
...
}
@GetMapping(“/”)
@应答器
公共响应实体getSomething(RequestEntity RequestEntity,
HttpServletRequest(请求){
log.info(“HTTP协议:+request.getProtocol());
...
}
谢谢你@Gimby。还找到了以下选项:
String httpVersion = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getProtocol;
@GetMapping("/")
@ResponseBody
public ResponseEntity<String> getSomething(RequestEntity requestEntity,
HttpServletRequest request) {
log.info("HTTP protocol: " + request.getProtocol());
...
}
String httpVersion = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getProtocol;