1. What does an HTTP HEAD request return?
Why: A HEAD request is like a GET request, but the server sends back only the headers. No body is returned.
2. Starting from which Spring version is the built-in support for HEAD and OPTIONS available?
Why: The built-in (implicit) support for HTTP HEAD and OPTIONS is available starting from Spring 4.3.
3. A URL already has a handler method for GET. Do you need to write a separate handler method for HEAD?
Why: Any request mapping that handles GET also supports HEAD implicitly. You do not need to declare HEAD separately.
4. What does Spring do when a HEAD request arrives for a URL mapped to a GET handler?
Why: Spring runs the same GET handler method, then discards the response body. Only the headers are sent back.
5. When an OPTIONS request arrives, which response header does Spring set to list the supported HTTP methods?
Why: Spring automatically sets the Allow header. It lists all HTTP methods that the URL supports.
6. A URL has no explicitly declared HTTP methods. What is the default value of the Allow header for an OPTIONS request?
Why: If no methods are declared for the URL, Spring uses all common methods: GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS.
7. A URL is mapped only for GET. What will the Allow header contain for an OPTIONS request?
Why: Spring adds HEAD because it supports HEAD for every GET mapping. It also adds OPTIONS. So the result is GET,HEAD,OPTIONS.
8. Why does HEAD appear in the Allow header when only GET was declared?
Why: A GET mapping automatically supports HEAD, so Spring includes HEAD in the Allow header.
9. Are your controller handler methods called when an OPTIONS request is handled by Spring's built-in support?
Why: For OPTIONS, no handler method is called. Spring only collects the supported methods for the URL and returns them in the Allow header.
10. For the implicit OPTIONS support to give a correct Allow header, what should each handler method for the URL do?
Why: The Allow header is built from the declared request mappings. So each handler method should explicitly specify its HTTP method.
11. Which curl option sends an HTTP HEAD request?
Why: The -I flag (or --head) tells curl to send a HEAD request. Only the headers are shown.