Javatar
Javatar

Reputation: 2665

Handling Http HEAD requests and header content - spring 3.1 mvc

I got a lot of 405 errors because I haven't support HEAD requests yet. Now while I try to fix this issue, the following question come to my head:

a) Is there an easier way to support HEAD for GET-URLs/resources? 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;
    }

or do I have to put a mapping for every Method?

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

b) What HTTP header attributes for HEAD should be supported? (rule of thumb?)

My actually reponse with: 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

Additional Info: Webshop, STS 3.1, JDK 6, JSR 2.5

Thanks.

Upvotes: 1

Views: 6427

Answers (2)

Kannan Mohan
Kannan Mohan

Reputation: 1850

Answering you (b) question. As a rule of thumb all header attributes/directives that are passed during a GET method should also be passed during a HEAD method call, and that is what the HTTP standard says.

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.  

Upvotes: 3

MinGyoo Jung
MinGyoo Jung

Reputation: 234

same question is here : Spring 3.0 HEAD Requests
shortly refer this : http://axelfontaine.com/blog/http-head.html

Upvotes: 2

Related Questions