- java.lang.Object
-
- com.github.mizosoft.methanol.ResponseBuilder<T>
-
- All Implemented Interfaces:
HeadersAccumulator<ResponseBuilder<T>>
public final class ResponseBuilder<T> extends java.lang.Object implements HeadersAccumulator<ResponseBuilder<T>>
A builder ofHttpResponseinstances.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ResponseBuilder<T>apply(java.util.function.Consumer<? super ResponseBuilder<T>> mutator)<U> ResponseBuilder<U>body(@Nullable U body)java.net.http.HttpResponse<T>build()CacheAwareResponse<T>buildCacheAwareResponse()TrackedResponse<T>buildTrackedResponse()ResponseBuilder<T>cacheResponse(@Nullable TrackedResponse<?> cacheResponse)ResponseBuilder<T>cacheStatus(CacheAwareResponse.CacheStatus cacheStatus)static <T> ResponseBuilder<T>create()Returns a newResponseBuilder.ResponseBuilder<T>dropBody()static <T> ResponseBuilder<T>from(java.net.http.HttpResponse<T> response)Returns a newResponseBuilderthat copies the given response's state.ResponseBuilder<T>header(java.lang.String name, java.lang.String value)Adds the given header name-value pair.ResponseBuilder<T>headers(java.lang.String... headers)Adds each of the given header name-value pairs.ResponseBuilder<T>headers(java.net.http.HttpHeaders headers)Adds all the given headers.ResponseBuilder<T>networkResponse(@Nullable TrackedResponse<?> networkResponse)ResponseBuilder<T>previousResponse(@Nullable java.net.http.HttpResponse<T> previousResponse)ResponseBuilder<T>removeHeader(java.lang.String name)Removes all the header values associated with the given name.ResponseBuilder<T>removeHeaders()Removes all the headers added so far.ResponseBuilder<T>removeHeadersIf(java.util.function.BiPredicate<java.lang.String,java.lang.String> filter)Removes all the header name-value pairs matched by the given predicate.ResponseBuilder<T>request(java.net.http.HttpRequest request)ResponseBuilder<T>setHeader(java.lang.String name, java.lang.String value)Sets the header represented by the given name to the given value, overwriting the previous value (if any).ResponseBuilder<T>setHeader(java.lang.String name, java.util.List<java.lang.String> values)Sets the header represented by the given name to the given values, overwriting the previous value (if any).ResponseBuilder<T>setHeaderIfAbsent(java.lang.String name, java.lang.String value)Sets the header represented by the given name to the given value, only if there was no header with the given name.ResponseBuilder<T>setHeaderIfAbsent(java.lang.String name, java.util.List<java.lang.String> values)Sets the header represented by the given name to the given values, only if there was no header with the given name.ResponseBuilder<T>sslSession(@Nullable javax.net.ssl.SSLSession sslSession)ResponseBuilder<T>statusCode(int statusCode)ResponseBuilder<T>timeRequestSent(java.time.Instant timeRequestSent)ResponseBuilder<T>timeResponseReceived(java.time.Instant timeResponseReceived)ResponseBuilder<T>uri(java.lang.String uri)ResponseBuilder<T>uri(java.net.URI uri)ResponseBuilder<T>version(java.net.http.HttpClient.Version version)
-
-
-
Method Detail
-
apply
@CanIgnoreReturnValue public ResponseBuilder<T> apply(java.util.function.Consumer<? super ResponseBuilder<T>> mutator)
-
statusCode
@CanIgnoreReturnValue public ResponseBuilder<T> statusCode(int statusCode)
-
uri
@CanIgnoreReturnValue public ResponseBuilder<T> uri(java.net.URI uri)
-
uri
@CanIgnoreReturnValue public ResponseBuilder<T> uri(java.lang.String uri)
-
version
@CanIgnoreReturnValue public ResponseBuilder<T> version(java.net.http.HttpClient.Version version)
-
header
@CanIgnoreReturnValue public ResponseBuilder<T> header(java.lang.String name, java.lang.String value)
Description copied from interface:HeadersAccumulatorAdds the given header name-value pair.- Specified by:
headerin interfaceHeadersAccumulator<T>
-
headers
@CanIgnoreReturnValue public ResponseBuilder<T> headers(java.lang.String... headers)
Description copied from interface:HeadersAccumulatorAdds each of the given header name-value pairs. The pairs must be appended to each other in the given array, where each name is followed by a corresponding value.- Specified by:
headersin interfaceHeadersAccumulator<T>
-
headers
@CanIgnoreReturnValue public ResponseBuilder<T> headers(java.net.http.HttpHeaders headers)
Description copied from interface:HeadersAccumulatorAdds all the given headers.- Specified by:
headersin interfaceHeadersAccumulator<T>
-
setHeader
@CanIgnoreReturnValue public ResponseBuilder<T> setHeader(java.lang.String name, java.lang.String value)
Description copied from interface:HeadersAccumulatorSets the header represented by the given name to the given value, overwriting the previous value (if any).- Specified by:
setHeaderin interfaceHeadersAccumulator<T>
-
setHeader
public ResponseBuilder<T> setHeader(java.lang.String name, java.util.List<java.lang.String> values)
Description copied from interface:HeadersAccumulatorSets the header represented by the given name to the given values, overwriting the previous value (if any).- Specified by:
setHeaderin interfaceHeadersAccumulator<T>
-
setHeaderIfAbsent
public ResponseBuilder<T> setHeaderIfAbsent(java.lang.String name, java.lang.String value)
Description copied from interface:HeadersAccumulatorSets the header represented by the given name to the given value, only if there was no header with the given name.- Specified by:
setHeaderIfAbsentin interfaceHeadersAccumulator<T>
-
setHeaderIfAbsent
public ResponseBuilder<T> setHeaderIfAbsent(java.lang.String name, java.util.List<java.lang.String> values)
Description copied from interface:HeadersAccumulatorSets the header represented by the given name to the given values, only if there was no header with the given name.- Specified by:
setHeaderIfAbsentin interfaceHeadersAccumulator<T>
-
removeHeaders
@CanIgnoreReturnValue public ResponseBuilder<T> removeHeaders()
Description copied from interface:HeadersAccumulatorRemoves all the headers added so far.- Specified by:
removeHeadersin interfaceHeadersAccumulator<T>
-
removeHeader
@CanIgnoreReturnValue public ResponseBuilder<T> removeHeader(java.lang.String name)
Description copied from interface:HeadersAccumulatorRemoves all the header values associated with the given name.- Specified by:
removeHeaderin interfaceHeadersAccumulator<T>
-
removeHeadersIf
@CanIgnoreReturnValue public ResponseBuilder<T> removeHeadersIf(java.util.function.BiPredicate<java.lang.String,java.lang.String> filter)
Description copied from interface:HeadersAccumulatorRemoves all the header name-value pairs matched by the given predicate.- Specified by:
removeHeadersIfin interfaceHeadersAccumulator<T>
-
request
@CanIgnoreReturnValue public ResponseBuilder<T> request(java.net.http.HttpRequest request)
-
timeRequestSent
@CanIgnoreReturnValue public ResponseBuilder<T> timeRequestSent(java.time.Instant timeRequestSent)
-
timeResponseReceived
@CanIgnoreReturnValue public ResponseBuilder<T> timeResponseReceived(java.time.Instant timeResponseReceived)
-
body
@CanIgnoreReturnValue public <U> ResponseBuilder<U> body(@Nullable U body)
-
dropBody
@CanIgnoreReturnValue public ResponseBuilder<T> dropBody()
-
sslSession
@CanIgnoreReturnValue public ResponseBuilder<T> sslSession(@Nullable javax.net.ssl.SSLSession sslSession)
-
previousResponse
@CanIgnoreReturnValue public ResponseBuilder<T> previousResponse(@Nullable java.net.http.HttpResponse<T> previousResponse)
-
networkResponse
@CanIgnoreReturnValue public ResponseBuilder<T> networkResponse(@Nullable TrackedResponse<?> networkResponse)
-
cacheResponse
@CanIgnoreReturnValue public ResponseBuilder<T> cacheResponse(@Nullable TrackedResponse<?> cacheResponse)
-
cacheStatus
@CanIgnoreReturnValue public ResponseBuilder<T> cacheStatus(CacheAwareResponse.CacheStatus cacheStatus)
-
build
public java.net.http.HttpResponse<T> build()
-
buildTrackedResponse
public TrackedResponse<T> buildTrackedResponse()
-
buildCacheAwareResponse
public CacheAwareResponse<T> buildCacheAwareResponse()
-
create
public static <T> ResponseBuilder<T> create()
Returns a newResponseBuilder.
-
from
public static <T> ResponseBuilder<T> from(java.net.http.HttpResponse<T> response)
Returns a newResponseBuilderthat copies the given response's state.
-
-