RFR: 8327796: Add method to java.net.http.HttpRequest to return a GET request in one call [v2]

Michael McMahon michaelm at openjdk.org
Tue Mar 12 21:45:15 UTC 2024


On Tue, 12 Mar 2024 16:21:56 GMT, Daniel Fuchs <dfuchs at openjdk.org> 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


More information about the net-dev mailing list