【问题标题】:Handling Http HEAD requests and header content - spring 3.1 mvc处理 Http HEAD 请求和标头内容 - spring 3.1 mvc
【发布时间】:2013-12-05 13:56:45
【问题描述】:

我收到很多 405 错误,因为我还不支持 HEAD 请求。现在,当我尝试解决此问题时,我想到了以下问题:

a) 有没有更简单的方法来支持 GET-URL/资源的 HEAD? http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

    @RequestMapping(value = "/**/p/{productCode}", method = RequestMethod.GET)
    public String productDetail(@PathVariable("productCode"), final Model model, final HttpServletRequest request) {

          // some stuff...          

          return ControllerConstants.GET_PRODUCT_DETAIL;
    }

或者我是否必须为每个方法放置一个映射?

@RequestMapping(value = "/**/p/{productCode}", method = RequestMethod.HEAD)
public String productDetailHead() {
      final HttpHeaders headers = new HttpHeaders();
      return new ResponseEntity(null, headers, HttpStatus.OK);
}

b) 应该支持 HEAD 的哪些 HTTP 标头属性? (经验法则?)

我的实际回应是: curl -I http://localhost:9001

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: _seaT.tenantID_=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: JSESSIONID=D07B464BBA02DC4148F00C5A08421B51; Path=/
Content-Length: 0
Date: Thu, 05 Dec 2013 13:41:42 GMT

附加信息: 网店、STS 3.1、JDK 6、JSR 2.5

谢谢。

【问题讨论】:

  • 请记住,HEAD 请求应该与 GET 请求执行相同的操作,但不提供响应正文。标头都应该与相应的 GET 请求的响应相同。

标签: java spring http spring-mvc http-headers


【解决方案1】:

回答您 (b) 的问题。根据经验,在 GET 方法期间传递的所有标头属性/指令也应在 HEAD 方法调用期间传递,这就是 HTTP 标准所说的。

The HEAD method is identical to GET except that the server MUST NOT
return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.  

【讨论】:

  • 好吧,我想我可以忍受。谢谢。
【解决方案2】:

同样的问题在这里:Spring 3.0 HEAD Requests
马上参考这个:http://axelfontaine.com/blog/http-head.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2010-09-06
    • 2012-12-02
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多