Summary
A new public Builder HEAD()
method is introduced on the
java.net.http.HttpRequest.Builder
interface.
Problem
The HTTPClient APIs in the java.net.http module allows applications
to create a HTTP client and issue HTTP requests. The
java.net.http.HttpRequest.Builder
interface has APIs which allow
applications to create such requests. Currently the
java.net.http.HttpRequest.Builder
has convenience methods like
GET()
, POST()
, DELETE()
and such. However, it is missing a
convenience method for creating a HEAD
request. Introducing a
HEAD()
method will make it consistent with these other available
methods and make it convenient for application use.
Solution
Since the java.net.http.HttpRequest.Builder
is a public interface
in a public module, the new HEAD() method will be introduced as a
"default" method. The default implementation expectation is that
it will call the "method(String method, BodyPublisher bodyPublisher)"
API that currently exists on the Builder interface, by passing it "HEAD" and
BodyPublishers.noBody()
as the parameters and return back whatever that
call returns.
Specification
diff --git a/src/java.net.http/share/classes/java/net/http/HttpRequest.java b/src/java.net.http/share/classes/java/net/http/HttpRequest.java
index 5dc0486826a..59174783263 100644
--- a/src/java.net.http/share/classes/java/net/http/HttpRequest.java
+++ b/src/java.net.http/share/classes/java/net/http/HttpRequest.java
+ /**
+ * Sets the request method of this builder to HEAD.
+ *
+ * @implSpec The default implementation is expected to have the same behaviour as:
+ * {@code return method("HEAD", BodyPublishers.noBody());}
+ *
+ * @return this builder
+ * @since 18
+ */
+ default Builder HEAD() {
+ return method("HEAD", BodyPublishers.noBody());
+ }
+
- csr of
-
JDK-8276559 (httpclient) Consider adding an HttpRequest.Builder.HEAD method to build a HEAD request.
- Resolved
- relates to
-
JDK-8181784 JEP 321: HTTP Client API
- Closed