Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8276559: (httpclient) Consider adding an HttpRequest.Builder.HEAD method to build a HEAD request. #6348

Closed
wants to merge 5 commits into from

Conversation

jaikiran
Copy link
Member

@jaikiran jaikiran commented Nov 11, 2021

Can I please get a review for this change which implements the enhancement noted in https://bugs.openjdk.java.net/browse/JDK-8276559?

The commit in this PR introduces a new HEAD() method on the HttpRequest.Builder interface. Given that this is a public interface on a public class of a public module, I decided to add this new method as a default method to prevent any potential breakages of any non-JDK implementations of this interface. The internal jdk.internal.net.http.HttpRequestBuilderImpl which implements this interface, overrides this default implementation to use an implementation of its own.

Existing tests have been updated to include coverage for this new method.

P.S: Slightly unrelated question - is it intentional that the Builder interface specifies the visibility modifiers on the interface methods. For example: public abstract Builder timeout(Duration duration);, public Builder headers(String... headers); and so on?


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8276559: (httpclient) Consider adding an HttpRequest.Builder.HEAD method to build a HEAD request.

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6348/head:pull/6348
$ git checkout pull/6348

Update a local copy of the PR:
$ git checkout pull/6348
$ git pull https://git.openjdk.java.net/jdk pull/6348/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6348

View PR using the GUI difftool:
$ git pr show -t 6348

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6348.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 11, 2021

👋 Welcome back jpai! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 11, 2021
@openjdk
Copy link

openjdk bot commented Nov 11, 2021

@jaikiran The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the net net-dev@openjdk.org label Nov 11, 2021
@mlbridge
Copy link

mlbridge bot commented Nov 11, 2021

Webrevs

@jaikiran
Copy link
Member Author

jaikiran commented Nov 11, 2021

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Nov 11, 2021
@openjdk
Copy link

openjdk bot commented Nov 11, 2021

@jaikiran has indicated that a compatibility and specification (CSR) request is needed for this pull request.
@jaikiran please create a CSR request for issue JDK-8276559. This pull request cannot be integrated until the CSR request is approved.

@jaikiran
Copy link
Member Author

jaikiran commented Nov 11, 2021

I've opened a CSR request for this change https://bugs.openjdk.java.net/browse/JDK-8276996

Copy link
Member

@sormuras sormuras left a comment

LGTM

Copy link
Member

@dfuch dfuch left a comment

Maybe test/jdk/java/net/httpclient/HeadTest.java could acquire a new dedicated method where HttpRequest.Builder.HEAD() is used. The test currently tests method("HEAD", BodyPublishers.noBody());

@@ -366,6 +379,7 @@ public static Builder newBuilder(HttpRequest request, BiPredicate<String, String
switch (method) {
case "GET" -> builder.GET();
case "DELETE" -> builder.DELETE();
case "HEAD" -> builder.HEAD();
Copy link
Member

@dfuch dfuch Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above (line 376) mentions:

                // otherwise, the body is absent, special case for GET/DELETE,
                // or else use empty body

maybe HEAD should be added there as well...

Copy link
Member Author

@jaikiran jaikiran Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I missed that. I've updated the PR to fix this.

@@ -121,6 +121,7 @@ record NamedAssertion(String name, BiConsumer<HttpRequest, HttpRequest> test) {
.headers("testName1", "z").build() },
// dedicated method
{ HttpRequest.newBuilder(URI.create("https://method-1/")).GET().build() },
{ HttpRequest.newBuilder(URI.create("https://method-1/")).HEAD().build() },
Copy link
Member

@dfuch dfuch Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to change the URI path to /method-0/ and move the HEAD case to just after line 122 (before GET)

Copy link
Member Author

@jaikiran jaikiran Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the updated version of the PR

@dfuch
Copy link
Member

dfuch commented Nov 12, 2021

P.S: Slightly unrelated question - is it intentional that the Builder interface specifies the visibility modifiers on the interface methods. For example: public abstract Builder timeout(Duration duration);, public Builder headers(String... headers); and so on?

Stylistic preference of the author - I guess (could be me). If this were a new class I would advise to remove the redundant qualifiers.

@jaikiran
Copy link
Member Author

jaikiran commented Nov 12, 2021

P.S: Slightly unrelated question - is it intentional that the Builder interface specifies the visibility modifiers on the interface methods. For example: public abstract Builder timeout(Duration duration);, public Builder headers(String... headers); and so on?

Stylistic preference of the author - I guess (could be me). If this were a new class I would advise to remove the redundant qualifiers.

Understood. I have the habit of using the public too sometimes. It was the presence of abstract in one of the methods which made me a bit curious.

@jaikiran
Copy link
Member Author

jaikiran commented Nov 12, 2021

Maybe test/jdk/java/net/httpclient/HeadTest.java could acquire a new dedicated method where HttpRequest.Builder.HEAD() is used. The test currently tests method("HEAD", BodyPublishers.noBody());

I've updated the HeadTest to include request building with the convenience methods too. While I was at it, I noticed that test had unused imports and unused fields. I cleaned them up too in the updated PR. I hope that's OK.
Finally, I also noticed that I missed adding a @bug to these updated tests, so I went ahead and added them in my updated PR.

@dfuch
Copy link
Member

dfuch commented Nov 12, 2021

P.S: Slightly unrelated question - is it intentional that the Builder interface specifies the visibility modifiers on the interface methods. For example: public abstract Builder timeout(Duration duration);, public Builder headers(String... headers); and so on?

Stylistic preference of the author - I guess (could be me). If this were a new class I would advise to remove the redundant qualifiers.

Understood. I have the habit of using the public too sometimes. It was the presence of abstract in one of the methods which made me a bit curious.

Oh - maybe it went back and forth from being an abstract class or an interface during prototyping...

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Nov 15, 2021
@jaikiran
Copy link
Member Author

jaikiran commented Nov 16, 2021

The CSR for this has been approved.

@dfuch
Copy link
Member

dfuch commented Nov 16, 2021

The changes look good. I'm going to give it a round of testing and I will approve if the results come clean.

dfuch
dfuch approved these changes Nov 16, 2021
Copy link
Member

@dfuch dfuch left a comment

LGTM

@openjdk
Copy link

openjdk bot commented Nov 16, 2021

@jaikiran This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8276559: (httpclient) Consider adding an HttpRequest.Builder.HEAD method to build a HEAD request.

Reviewed-by: cstein, dfuchs

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 52 new commits pushed to the master branch:

  • d5e47d6: 8277089: Use system binutils to build hsdis
  • f3eb501: 8276162: Optimise unsigned comparison pattern
  • 9a9a157: 8276905: Use appropriate macosx_version_minimum value while compiling metal shaders
  • 7906eb0: 8277119: Add asserts in GenericTaskQueueSet methods
  • 1c45c8a: 8274757: Cleanup unnecessary calls to Throwable.initCause() in java.management module
  • c06df25: 8274662: Replace 'while' cycles with iterator with enhanced-for in jdk.hotspot.agent
  • 9629627: 8274163: Use String.equals instead of String.compareTo in jdk.jcmd
  • 0bc2683: 8274190: Use String.equals instead of String.compareTo in jdk.internal.jvmstat
  • a9cb8bd: 8274168: Avoid String.compareTo == 0 to check String equality in java.management
  • 20f3872: 8274261: Use enhanced-for instead of plain 'for' in jdk.jcmd
  • ... and 42 more: https://git.openjdk.java.net/jdk/compare/aea096770e74b9c0e1556467705ffdd6cf843d9d...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 16, 2021
@jaikiran
Copy link
Member Author

jaikiran commented Nov 17, 2021

Thank you Daniel and @sormuras for the reviews.

@jaikiran
Copy link
Member Author

jaikiran commented Nov 17, 2021

/integrate

@openjdk
Copy link

openjdk bot commented Nov 17, 2021

Going to push as commit 23e5117.
Since your change was applied there have been 57 commits pushed to the master branch:

  • a77d8dd: 8276787: Improve warning messages for -XX:+RecordDynamicDumpInfo
  • 8ed384c: 8276609: Document setting property jdk.serialFilter to an invalid value throws ExceptionInInitializerError
  • cddc6ce: 8275811: Incorrect instance to dispose
  • b0a463f: 8169468: NoResizeEventOnDMChangeTest.java fails because FS Window didn't receive all resizes!
  • e5ffdf9: 8276231: ciReplay: SIGSEGV when replay compiling lambdas
  • d5e47d6: 8277089: Use system binutils to build hsdis
  • f3eb501: 8276162: Optimise unsigned comparison pattern
  • 9a9a157: 8276905: Use appropriate macosx_version_minimum value while compiling metal shaders
  • 7906eb0: 8277119: Add asserts in GenericTaskQueueSet methods
  • 1c45c8a: 8274757: Cleanup unnecessary calls to Throwable.initCause() in java.management module
  • ... and 47 more: https://git.openjdk.java.net/jdk/compare/aea096770e74b9c0e1556467705ffdd6cf843d9d...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Nov 17, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 17, 2021
@openjdk
Copy link

openjdk bot commented Nov 17, 2021

@jaikiran Pushed as commit 23e5117.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jaikiran jaikiran deleted the 8276559 branch Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated net net-dev@openjdk.org
3 participants