-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
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 (seeJDK-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.
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
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.
- relates to
-
JDK-8308364 HttpClientImpl SelectorManager thread never dies if response body not retrieved
- Closed
-
JDK-8327991 Improve HttpClient documentation with regard to reclaiming resources
- Resolved