On Tue, 12 Mar 2024 16:21:56 GMT, Daniel Fuchs <[email protected]> wrote:

>> src/java.net.http/share/classes/java/net/http/HttpResponse.java line 153:
>> 
>>> 151:      * @return an Optional containing the response body if the 
>>> predicate returns true
>>> 152:      */
>>> 153:     public Optional<T> bodyWhen(Predicate<ResponseInfo> predicate) 
>>> throws IOException;
>> 
>> This is a neat idea which will allow to append additional steps like 
>> `.orElseThrows(...)` etc...
>
> I wonder if it should be a `Predicate<HttpResponse>` instead?

No, we added `HttpResponse.ResponseInfo` for this kind of purpose. It's an 
immutable subset of HttpResponse state (notably excluding the body itself which 
is potentially mutable). Also it would be strange to make the body available to 
a predicate that is deciding whether to provide access to the body.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18227#discussion_r1522152016

Reply via email to