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

HttpClient: find a way to promote autoclosing of streaming bodies created by BodyHandlers

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • None
    • core-libs

    Description

      The HttpClent APIs provide BodyHandler / BodySubscriber implementations (also called streaming handlers / subscribers) that return response bodies in the form of InputStreams or j.u.s.Streams, making it possible to turn a reactive API into a pull API. These streaming bodies are also AutoCloseable.

      However, the catch is that these AutoCloseable bodies need imperatively to be closed, or the data they relay need to be completely consumed, in order to release the underlying resources that keep the HttpClient alive (see JDK-8308364).

      Several possibility could be envisaged to make the API more user friendly. For instance:

        - make HttpResponse AutoCloseable (or Closeable)
        - provide ways to compose/combine BodyHandlers / BodySubscribers so that different implementations could be combined depending on response code or response headers
        - use Cleaner/Cleanable to cancel the body subscription if the object returned by HttpResponse::body becomes unreachable.
        - other?

      Each one has its pros and cons and would need to be discussed before settling on a solution.

      Attachments

        Issue Links

          Activity

            People

              dfuchs Daniel Fuchs
              dfuchs Daniel Fuchs
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: