Spring 3.0 HEAD Requests

前端 未结 3 960
广开言路
广开言路 2021-01-03 23:35

recently we moved to spring 3.0 Controller handling like this:

@Controller
public class MyController {
   @RequestMapping(method = RequestMethod.POST)
   pro         


        
相关标签:
3条回答
  • 2021-01-03 23:45

    I believe this is what you're looking for: http://www.axelfontaine.com/2009/09/transparently-supporting-http-head.html

    0 讨论(0)
  • 2021-01-03 23:47

    In the current Spring (4.3.10) HEAD is automatically supported:

    @RequestMapping methods mapped to "GET" are also implicitly mapped to "HEAD", i.e. there is no need to have "HEAD" explicitly declared. An HTTP HEAD request is processed as if it were an HTTP GET except instead of writing the body only the number of bytes are counted and the "Content-Length" header set.

    https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-requestmapping-head-options

    0 讨论(0)
  • 2021-01-04 00:00

    Just add HEAD as a supported method the the request mapping:

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.HEAD})
    

    Update: I think you can provide a custom class that extends AnnotationMethodHandlerAdapter to be the method handler (in dispatcher-servlet.xml), and just bypass the HEAD support check there. But I'd just use the replace features of an IDE to add it.

    0 讨论(0)
提交回复
热议问题