JDK-8276559 : (httpclient) Consider adding an HttpRequest.Builder.HEAD method to build a HEAD request.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-11-03
  • Updated: 2024-04-04
  • Resolved: 2021-11-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18 b24Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Description
HttpRequest.Builder has GET, PUT, POST, DELETE, not sure why we didn't include HEAD.
In the meantime, to build a HEAD request simply use `HttpRequest.Builder.method("HEAD", BodyPublishers.noBody())`;
Comments
Changeset: 23e5117a Author: Jaikiran Pai <jpai@openjdk.org> Date: 2021-11-17 03:20:40 +0000 URL: https://git.openjdk.java.net/jdk/commit/23e5117a55b3f3d0e3d26bf2d481f4ad1c99af57
17-11-2021

Hi Jaikiran, CONNECT is a restricted method in the java.net.HttpClient - so we will never add that. We could consider adding OPTIONS and TRACE too - however, given that these methods may take a body you don't have the unpleasantness of figuring out that you'd need to supply an additional `BodyPublishers.noBody()` when calling `HttpRequest.Builder::method` as is the case when you want to send a "HEAD" request. Also TRACE has some verbiage about not sending credentials or cookies, so we might have to specify that this is the sole responsibility of the caller when configuring the HttpClient with an Authenticator or CookieHandler. So I'm not sure it would be worth adding them.
11-11-2021

Hello Daniel, RFC-7231 in section 4.1 https://datatracker.ietf.org/doc/html/rfc7231#section-4.1 has a table which lists the standardized methods. They are GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS and TRACE. If a HEAD() method is added to the HttpRequest.Builder class, should there be consideration for adding OPTIONS(), TRACE() and CONNECT() methods too (of course with relevant parameters if appropriate)?
11-11-2021