Issue
The following annotations are included in the Spring Framework:
@GetMapping
, @PostMapping
, @PutMapping
, @DeleteMapping
and @PatchMapping
for standard Spring MVC controller methods. However @HeadMapping
is not. What's the point about this?
Solution
According to W3 Standard for HEAD Request
9.4 HEAD
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.
It is a Request Method that is similar to GET
but should not return a Body. Thus your GET
method will effectively handle the HEAD
method also but with the exception of not returning a response body.
So ideally you can use @GetMapping
to handle HEAD
request methods and can have a Filter
to avoid returning the response back to the calling client as discussed in this post
Answered By - shazin