Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8191917

Refresh incubating HTTP Client

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P2 P2
    • 10
    • core-libs
    • None
    • minimal
    • This is an incubating API. Change should not be surprising.
    • Java API
    • JDK

      Summary

      Refresh the incubating Http Client API.

      Problem

      As the API is still incubating ( in the jdk.incubator.http package ), there have been several API tweaks. Mainly renaming ( request & response body processors are now request publisher and response subscriber ), minor spec clarifications around exceptions, a general tidy up and changes to address a number of external feedback items.

      Solution

      The processors that deal with request and response bodies have need renamed to closer align with their RX counterparts that they inherit from. This increasing readability of code that uses these types directly:

      • HttpRequest.BodyProcessor -> HttpRequest.BodyPublisher
      • HttpResponse.BodyProcessor -> HttpResponse.BodySubscriber
      • HttpResponse.MultiProcessor -> HttpResponse.MultiSubscriber

      HttpClient, and its builder HttpClient.Builder, follow a pattern where configuration set on the builder is retrievable from the client, while implementation specific defaults are not. This is generally more secure, and more easily facilities implementation specific behavior, e.g. support for system proxies by default.

      A new convenience response body handler/subscriber, asInputStream, that provides a bridge to the blocking input stream API, has been added, as a result of feedback from the community.

      The equals and hashCode methods have been defined for HttpRequest since it appears as a key in a Map parameter type.

      To be more friendly for testing and mocking, HttpHeader has been changed from an interface to an abstract class with all-but-one methods having a default implementation. It is also necessary to define its equals and hashCode, since it is part of the equality of an HttpRequest.

      The HttpResponse class been reworked to provide better visibility into intermediate responses, e.g. redirection, authentication, etc. The finalRequest method has been replaced with previousResponse, that support retrieval of all intermediate responses and their headers.

      WebSocket, and related nested types, have had the wording in their specification overhauled, to improve readability. Additionally, the WebSocket.isClosed method has been replaced with isInputClosed and isOutputClosed, as a result of feedback from the community.

      Use of CookieManager has been replaced with the more general type CookieHandler.

      Specification

      Attached specdiff.zip, or online at http://cr.openjdk.java.net/~chegar/http_client_sandbox_8191494/specdiff/overview-summary.html

            chegar Chris Hegarty
            chegar Chris Hegarty
            Alan Bateman, Daniel Fuchs, Michael McMahon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: