Interface HttpResponse
- All Superinterfaces:
HttpMessage,org.reactivestreams.Publisher<HttpObject>,Response,StreamMessage<HttpObject>
- All Known Subinterfaces:
HttpResponseWriter
- All Known Implementing Classes:
FilteredHttpResponse
Response.-
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<AggregatedHttpResponse> Aggregates this response.aggregate(AggregationOptions options) Aggregates this response with the specifiedAggregationOptions.default CompletableFuture<AggregatedHttpResponse> aggregate(EventExecutor executor) Aggregates this response.default CompletableFuture<AggregatedHttpResponse> Deprecated.default CompletableFuture<AggregatedHttpResponse> aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc) Deprecated.static HttpResponseBuilderbuilder()Returns a newHttpResponseBuilder.static HttpResponsedelayed(AggregatedHttpResponse response, Duration delay) Creates a new HTTP response that delegates to the providedAggregatedHttpResponse, beginning publishing afterdelayhas passed from a randomScheduledExecutorService.static HttpResponsedelayed(AggregatedHttpResponse response, Duration delay, ScheduledExecutorService executor) Creates a new HTTP response that delegates to the providedAggregatedHttpResponse, beginning publishing afterdelayhas passed from the providedScheduledExecutorService.static HttpResponsedelayed(HttpResponse response, Duration delay) Creates a new HTTP response that delegates to the providedHttpResponse, beginning publishing afterdelayhas passed from a randomScheduledExecutorService.static HttpResponsedelayed(HttpResponse response, Duration delay, ScheduledExecutorService executor) Creates a new HTTP response that delegates to the providedHttpResponse, beginning publishing afterdelayhas passed from the providedScheduledExecutorService.static HttpResponsedelayed(Supplier<? extends HttpResponse> responseSupplier, Duration delay) Invokes the specifiedSupplierand creates a new HTTP response that delegates to the providedHttpResponsebySupplier.static HttpResponsedelayed(Supplier<? extends HttpResponse> responseSupplier, Duration delay, ScheduledExecutorService executor) Invokes the specifiedSupplierand creates a new HTTP response that delegates to the providedHttpResponseSupplier, beginning publishing afterdelayhas passed from the providedScheduledExecutorService.static HttpResponsefrom(CompletableFuture<? extends HttpResponse> future) Deprecated.Useof(CompletionStage).static HttpResponsefrom(CompletionStage<? extends HttpResponse> stage) Deprecated.Useof(CompletionStage).static HttpResponsefrom(CompletionStage<? extends HttpResponse> stage, EventExecutor subscriberExecutor) Deprecated.static HttpResponsefrom(Supplier<? extends HttpResponse> responseSupplier, Executor executor) Deprecated.default HttpResponsedefault HttpResponseTransforms an error emitted by thisHttpResponseby applying the specifiedFunction.default HttpResponsemapHeaders(Function<? super ResponseHeaders, ? extends ResponseHeaders> function) Transforms the non-informationalResponseHeadersemitted byHttpResponseby applying the specifiedFunction.default HttpResponsemapInformational(Function<? super ResponseHeaders, ? extends ResponseHeaders> function) default HttpResponsemapTrailers(Function<? super HttpHeaders, ? extends HttpHeaders> function) static HttpResponseof(int statusCode) Creates a new HTTP response of the specifiedstatusCode.static HttpResponseof(HttpObject... objs) Creates a new HTTP response of the specified objects.static HttpResponseof(HttpStatus status) Creates a new HTTP response of the specifiedHttpStatus.static HttpResponseof(HttpStatus status, MediaType mediaType, byte[] content) Creates a new HTTP response of the specifiedHttpStatus.static HttpResponseof(HttpStatus status, MediaType mediaType, HttpData content) Creates a new HTTP response of the specifiedHttpStatus.static HttpResponseof(HttpStatus status, MediaType mediaType, HttpData content, HttpHeaders trailers) Creates a new HTTP response of the specifiedHttpStatus.static HttpResponseof(HttpStatus status, MediaType mediaType, CharSequence content) Creates a new HTTP response of the specifiedHttpStatus.static HttpResponseof(HttpStatus status, MediaType mediaType, String content) Creates a new HTTP response of the specifiedHttpStatus.static HttpResponseof(HttpStatus status, MediaType mediaType, String format, Object... args) Creates a new HTTP response of the specifiedHttpStatus.static HttpResponseCreates a new HTTP response of OK status with the content.static HttpResponseCreates a new HTTP response of OK status with the content.static HttpResponseof(ResponseHeaders headers) Creates a new HTTP response of the specified headers.static HttpResponseof(ResponseHeaders headers, HttpData content) Creates a new HTTP response of the specified headers and content.static HttpResponseof(ResponseHeaders headers, HttpData content, HttpHeaders trailers) Creates a new HTTP response of the specified objects.static HttpResponseof(ResponseHeaders headers, org.reactivestreams.Publisher<? extends HttpData> publisher, HttpHeaders trailers) Creates a new HTTP response with the specified headers and trailers whose stream is produced from an existingPublisher.static HttpResponseof(ResponseHeaders headers, org.reactivestreams.Publisher<? extends HttpData> publisher, Function<@Nullable Throwable, HttpHeaders> trailersFunction) Creates a new HTTP response with the specified headers and trailers function whose stream is produced from an existingPublisher.static HttpResponseof(ResponseHeaders headers, org.reactivestreams.Publisher<? extends HttpObject> publisher) Creates a new HTTP response with the specified headers whose stream is produced from an existingPublisher.static HttpResponseCreates a new HTTP response of OK status with the content as UTF_8.static HttpResponseCreates a new HTTP response of OK status with the content as UTF_8.static HttpResponseof(CompletableFuture<? extends HttpResponse> future) Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletableFuture.static HttpResponseof(CompletionStage<? extends HttpResponse> stage) Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletionStage.static HttpResponseof(CompletionStage<? extends HttpResponse> stage, EventExecutor subscriberExecutor) Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletionStage.static HttpResponseof(Supplier<? extends HttpResponse> responseSupplier, Executor executor) Creates a new HTTP response that delegates to theHttpResponseprovided by theSupplier.static HttpResponseof(org.reactivestreams.Publisher<? extends HttpObject> publisher) Creates a new HTTP response whose stream is produced from an existingPublisher.static HttpResponseCreates a new failed HTTP response.static HttpResponseofJson(HttpStatus status, MediaType contentType, Object content) Creates a new HTTP response with the specifiedHttpStatus,MediaTypeandcontentthat is converted into JSON using the defaultObjectMapper.static HttpResponseofJson(HttpStatus status, Object content) Creates a new HTTP response with the specifiedHttpStatusandcontentthat is converted into JSON using the defaultObjectMapper.static HttpResponseCreates a new HTTP response with the specifiedMediaTypeandcontentthat is converted into JSON using the defaultObjectMapper.static HttpResponseofJson(ResponseHeaders headers, Object content) Creates a new HTTP response with the specifiedResponseHeadersandcontentthat is converted into JSON using the defaultObjectMapper.static HttpResponseCreates a new HTTP response with the specifiedcontentthat is converted into JSON using the defaultObjectMapper.static HttpResponseofRedirect(HttpStatus redirectStatus, String location) Creates a new HTTP response of the redirect to specific location.static HttpResponseofRedirect(HttpStatus redirectStatus, String format, Object... args) Creates a new HTTP response of the redirect to specific location using string format.static HttpResponseofRedirect(String location) Creates a new HTTP response of the temporary redirect to specific location.static HttpResponseofRedirect(String format, Object... args) Creates a new HTTP response of the temporary redirect to specific location using string format.default HttpResponsedefault HttpResponseApplies the specifiedConsumerto an error emitted by thisHttpResponse.default HttpResponsepeekHeaders(Consumer<? super ResponseHeaders> action) Applies the specifiedConsumerto the non-informationalResponseHeadersemitted by thisHttpResponse.default HttpResponsepeekTrailers(Consumer<? super HttpHeaders> action) default <T extends Throwable>
HttpResponserecover(Class<T> causeClass, Function<? super T, ? extends HttpResponse> function) Recovers a failedHttpResponseby switching to a returned fallbackHttpResponsewhen the thrownThrowableis the same type or a subtype of the specifiedcauseClass.default HttpResponserecover(Function<? super Throwable, ? extends HttpResponse> function) Recovers a failedHttpResponseby switching to a returned fallbackHttpResponsewhen any error occurs before aResponseHeadersis written.default SplitHttpResponsesplit()default SplitHttpResponsesplit(EventExecutor executor) static HttpResponseWriterCreates a new HTTP response that can stream an arbitrary number ofHttpObjectto the client.default HttpResponsesubscribeOn(EventExecutor eventExecutor) CallsStreamMessage.subscribe(Subscriber, EventExecutor)to the upstreamStreamMessageusing the specifiedEventExecutorand relays the stream transparently downstream.default HttpResponseDuplicatorReturns a newStreamMessageDuplicatorthat duplicates thisStreamMessageinto one or moreStreamMessages, which publish the same elements.default HttpResponseDuplicatortoDuplicator(long maxResponseLength) Returns a newStreamMessageDuplicatorthat duplicates thisHttpMessageinto one or moreHttpMessages, which publish the same elements.default HttpResponseDuplicatortoDuplicator(EventExecutor executor) Returns a newStreamMessageDuplicatorthat duplicates thisStreamMessageinto one or moreStreamMessages, which publish the same elements.default HttpResponseDuplicatortoDuplicator(EventExecutor executor, long maxResponseLength) Returns a newStreamMessageDuplicatorthat duplicates thisHttpMessageinto one or moreHttpMessages, which publish the same elements.Returns aCompletableFuturewhich completes when 1) the response stream has been closed (theStreamMessagehas been completed) or 2) the result value is set (theCompletionStagehas completed.)Methods inherited from interface com.linecorp.armeria.common.HttpMessage
decode, decodeMethods inherited from interface com.linecorp.armeria.common.stream.StreamMessage
abort, abort, collect, collect, collect, decode, decode, defaultSubscriberExecutor, demand, endWith, filter, flatMap, flatMap, isComplete, isEmpty, isOpen, map, mapAsync, mapParallel, mapParallel, peek, peek, recoverAndResume, recoverAndResume, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, toInputStream, toInputStream, writeTo
-
Method Details
-
streaming
Creates a new HTTP response that can stream an arbitrary number ofHttpObjectto the client. The first object written must be of typeResponseHeaders. -
from
Deprecated.Useof(CompletionStage).Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletionStage. If the specifiedCompletionStagefails, the returned response will be closed with the same cause as well.- Parameters:
stage- theCompletionStagewhich will produce the actualHttpResponse
-
from
Deprecated.Useof(CompletionStage).Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletableFuture. If the specifiedCompletableFuturefails, the returned response will be closed with the same cause as well.- Parameters:
future- theCompletableFuturewhich will produce the actualHttpResponse
-
from
@Deprecated static HttpResponse from(CompletionStage<? extends HttpResponse> stage, EventExecutor subscriberExecutor) Deprecated.Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletionStage. If the specifiedCompletionStagefails, the returned response will be closed with the same cause as well.- Parameters:
stage- theCompletionStagewhich will produce the actualHttpResponsesubscriberExecutor- theEventExecutorwhich will be used when a user subscribes the returnedHttpResponseusingStreamMessage.subscribe(Subscriber)orStreamMessage.subscribe(Subscriber, SubscriptionOption...).
-
from
@Deprecated static HttpResponse from(Supplier<? extends HttpResponse> responseSupplier, Executor executor) Deprecated.Creates a new HTTP response that delegates to theHttpResponseprovided by theSupplier.- Parameters:
responseSupplier- theSupplierinvokes returning the providedHttpResponseexecutor- theExecutorthat executes theSupplier.
-
delayed
Creates a new HTTP response that delegates to the providedAggregatedHttpResponse, beginning publishing afterdelayhas passed from a randomScheduledExecutorService. -
delayed
static HttpResponse delayed(AggregatedHttpResponse response, Duration delay, ScheduledExecutorService executor) Creates a new HTTP response that delegates to the providedAggregatedHttpResponse, beginning publishing afterdelayhas passed from the providedScheduledExecutorService. -
delayed
Creates a new HTTP response that delegates to the providedHttpResponse, beginning publishing afterdelayhas passed from a randomScheduledExecutorService. -
delayed
static HttpResponse delayed(HttpResponse response, Duration delay, ScheduledExecutorService executor) Creates a new HTTP response that delegates to the providedHttpResponse, beginning publishing afterdelayhas passed from the providedScheduledExecutorService. -
delayed
Invokes the specifiedSupplierand creates a new HTTP response that delegates to the providedHttpResponsebySupplier.The
Supplieris invoked from the current thread-localRequestContext's event loop. If there's no thread localRequestContextis set, one of the threads fromCommonPools.workerGroup().next()will be used. -
delayed
static HttpResponse delayed(Supplier<? extends HttpResponse> responseSupplier, Duration delay, ScheduledExecutorService executor) Invokes the specifiedSupplierand creates a new HTTP response that delegates to the providedHttpResponseSupplier, beginning publishing afterdelayhas passed from the providedScheduledExecutorService. -
of
Creates a new HTTP response of the specifiedstatusCode.- Throws:
IllegalArgumentException- if the specifiedstatusCodeis informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus.- Throws:
IllegalArgumentException- if the specifiedHttpStatusis informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus.- Parameters:
mediaType- theMediaTypeof the response contentcontent- the content of the response- Throws:
IllegalArgumentException- if the specifiedHttpStatusis informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus.- Parameters:
mediaType- theMediaTypeof the response contentcontent- the content of the response- Throws:
IllegalArgumentException- if the specifiedHttpStatusis informational.
-
of
Creates a new HTTP response of OK status with the content as UTF_8.- Parameters:
content- the content of the response
-
of
Creates a new HTTP response of OK status with the content as UTF_8. The content of the response is formatted byString.format(Locale, String, Object...)with English locale.- Parameters:
format- the format string of the response contentargs- the arguments referenced by the format specifiers in the format string
-
of
Creates a new HTTP response of OK status with the content.- Parameters:
mediaType- theMediaTypeof the response contentcontent- the content of the response
-
of
@FormatMethod static HttpResponse of(MediaType mediaType, @FormatString String format, Object... args) Creates a new HTTP response of OK status with the content. The content of the response is formatted byString.format(Locale, String, Object...)with English locale.- Parameters:
mediaType- theMediaTypeof the response contentformat- the format string of the response contentargs- the arguments referenced by the format specifiers in the format string
-
of
@FormatMethod static HttpResponse of(HttpStatus status, MediaType mediaType, @FormatString String format, Object... args) Creates a new HTTP response of the specifiedHttpStatus. The content of the response is formatted byString.format(Locale, String, Object...)with English locale.- Parameters:
mediaType- theMediaTypeof the response contentformat- the format string of the response contentargs- the arguments referenced by the format specifiers in the format string- Throws:
IllegalArgumentException- if the specifiedHttpStatusis informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus. Thecontentwill be wrapped usingHttpData.wrap(byte[]), so any changes made tocontentwill be reflected in the response.- Parameters:
mediaType- theMediaTypeof the response contentcontent- the content of the response- Throws:
IllegalArgumentException- if the specifiedHttpStatusis informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus.- Parameters:
mediaType- theMediaTypeof the response contentcontent- the content of the response- Throws:
IllegalArgumentException- if the specifiedHttpStatusis informational.
-
of
static HttpResponse of(HttpStatus status, MediaType mediaType, HttpData content, HttpHeaders trailers) Creates a new HTTP response of the specifiedHttpStatus.- Parameters:
mediaType- theMediaTypeof the response contentcontent- the content of the responsetrailers- the HTTP trailers- Throws:
IllegalArgumentException- if the specifiedHttpStatusis informational.
-
of
Creates a new HTTP response of the specified headers.- Throws:
IllegalArgumentException- if the status of the specifiedResponseHeadersis informational.
-
of
Creates a new HTTP response of the specified headers and content.- Throws:
IllegalArgumentException- if the status of the specifiedResponseHeadersis informational.
-
of
Creates a new HTTP response of the specified objects.- Throws:
IllegalArgumentException- if the status of the specifiedResponseHeadersis informational.
-
of
Creates a new HTTP response of the specified objects. -
of
Creates a new HTTP response whose stream is produced from an existingPublisher.Note that the
HttpObjects in thePublisherare not released whenSubscription.cancel()orStreamMessage.abort()is called. You should add a hook in order to release the elements. SeePublisherBasedStreamMessagefor more information. -
of
static HttpResponse of(ResponseHeaders headers, org.reactivestreams.Publisher<? extends HttpObject> publisher) Creates a new HTTP response with the specified headers whose stream is produced from an existingPublisher.Note that the
HttpObjects in thePublisherare not released whenSubscription.cancel()orStreamMessage.abort()is called. You should add a hook in order to release the elements. SeePublisherBasedStreamMessagefor more information. -
of
static HttpResponse of(ResponseHeaders headers, org.reactivestreams.Publisher<? extends HttpData> publisher, HttpHeaders trailers) Creates a new HTTP response with the specified headers and trailers whose stream is produced from an existingPublisher.Note that the
HttpDatas in thePublisherare not released whenSubscription.cancel()orStreamMessage.abort()is called. You should add a hook in order to release the elements. SeePublisherBasedStreamMessagefor more information. -
of
static HttpResponse of(ResponseHeaders headers, org.reactivestreams.Publisher<? extends HttpData> publisher, Function<@Nullable Throwable, HttpHeaders> trailersFunction) Creates a new HTTP response with the specified headers and trailers function whose stream is produced from an existingPublisher.Note that the
HttpDatas in thePublisherare not released whenSubscription.cancel()orStreamMessage.abort()is called. You should add a hook in order to release the elements. SeePublisherBasedStreamMessagefor more information. -
of
Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletableFuture. If the specifiedCompletableFuturefails, the returned response will be closed with the same cause as well.- Parameters:
future- theCompletableFuturewhich will produce the actualHttpResponse
-
of
Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletionStage. If the specifiedCompletionStagefails, the returned response will be closed with the same cause as well.- Parameters:
stage- theCompletionStagewhich will produce the actualHttpResponse
-
of
static HttpResponse of(CompletionStage<? extends HttpResponse> stage, EventExecutor subscriberExecutor) Creates a new HTTP response that delegates to theHttpResponseproduced by the specifiedCompletionStage. If the specifiedCompletionStagefails, the returned response will be closed with the same cause as well.- Parameters:
stage- theCompletionStagewhich will produce the actualHttpResponsesubscriberExecutor- theEventExecutorwhich will be used when a user subscribes the returnedHttpResponseusingStreamMessage.subscribe(Subscriber)orStreamMessage.subscribe(Subscriber, SubscriptionOption...).
-
of
Creates a new HTTP response that delegates to theHttpResponseprovided by theSupplier.- Parameters:
responseSupplier- theSupplierinvokes returning the providedHttpResponseexecutor- theExecutorthat executes theSupplier.
-
ofJson
Creates a new HTTP response with the specifiedcontentthat is converted into JSON using the defaultObjectMapper.- Throws:
IllegalArgumentException- if failed to encode thecontentinto JSON.- See Also:
-
ofJson
Creates a new HTTP response with the specifiedHttpStatusandcontentthat is converted into JSON using the defaultObjectMapper.- Throws:
IllegalArgumentException- if failed to encode thecontentinto JSON.- See Also:
-
ofJson
Creates a new HTTP response with the specifiedMediaTypeandcontentthat is converted into JSON using the defaultObjectMapper.- Throws:
IllegalArgumentException- if the specifiedMediaTypeis not a JSON compatible type; or if failed to encode thecontentinto JSON.- See Also:
-
ofJson
Creates a new HTTP response with the specifiedHttpStatus,MediaTypeandcontentthat is converted into JSON using the defaultObjectMapper.- Throws:
IllegalArgumentException- if the specifiedMediaTypeis not a JSON compatible type; or if failed to encode thecontentinto JSON.- See Also:
-
ofJson
Creates a new HTTP response with the specifiedResponseHeadersandcontentthat is converted into JSON using the defaultObjectMapper.- Throws:
IllegalArgumentException- if failed to encode thecontentinto JSON.- See Also:
-
ofRedirect
Creates a new HTTP response of the redirect to specific location. -
ofRedirect
Creates a new HTTP response of the redirect to specific location using string format. -
ofRedirect
Creates a new HTTP response of the temporary redirect to specific location. -
ofRedirect
Creates a new HTTP response of the temporary redirect to specific location using string format. -
ofFailure
Creates a new failed HTTP response. -
builder
Returns a newHttpResponseBuilder. -
whenComplete
CompletableFuture<Void> whenComplete()Description copied from interface:ResponseReturns aCompletableFuturewhich completes when 1) the response stream has been closed (theStreamMessagehas been completed) or 2) the result value is set (theCompletionStagehas completed.)- Specified by:
whenCompletein interfaceResponse- Specified by:
whenCompletein interfaceStreamMessage<HttpObject>
-
aggregate
Aggregates this response with the specifiedAggregationOptions. The returnedCompletableFuturewill be notified when the content and the trailers of the response are fully received.AggregationOptions options = AggregationOptions.builder() .cacheResult(false) .executor(...) .build(); HttpResponse request = ...; AggregatedHttpResponse aggregated = response.aggregate(options).join(); -
aggregate
Aggregates this response. The returnedCompletableFuturewill be notified when the content and the trailers of the response are received fully.The
AggregatedHttpResponseis cached by default. So it is allowed to repeatedly call this method and get the cached value after the first aggregation.HttpResponse response = ...; AggregatedHttpResponse aggregated0 = response.aggregate().join(); AggregatedHttpResponse aggregated1 = response.aggregate().join(); assert aggregated0 == aggregated1; -
aggregate
Aggregates this response. The returnedCompletableFuturewill be notified when the content and the trailers of the response are received fully.The
AggregatedHttpResponseis cached by default. So it is allowed to repeatedly call this method and get the cached value after the first aggregation.HttpResponse response = ...; AggregatedHttpResponse aggregated0 = response.aggregate(executor).join(); AggregatedHttpResponse aggregated1 = response.aggregate(executor).join(); assert aggregated0 == aggregated1; -
aggregateWithPooledObjects
@Deprecated @UnstableApi default CompletableFuture<AggregatedHttpResponse> aggregateWithPooledObjects(ByteBufAllocator alloc) Deprecated.(Advanced users only) Aggregates this response. The returnedCompletableFuturewill be notified when the content and the trailers of the response are received fully.AggregatedHttpObject.content()will return a pooled object, and the caller must ensure to release it. If you don't know what this means, useaggregate().The pooled
AggregatedHttpResponseis not cached. So it is NOT allowed to access theAggregatedHttpResponsefrom this method after the first aggregation.HttpResponse response = ...; AggregatedHttpResponse aggregated = response.aggregateWithPooledObjects(alloc).join(); // An `IllegalStateException` will be raised. response.aggregateWithPooledObjects(alloc).join();- See Also:
-
aggregateWithPooledObjects
@Deprecated default CompletableFuture<AggregatedHttpResponse> aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc) Deprecated.Aggregates this response. The returnedCompletableFuturewill be notified when the content and the trailers of the response is received fully.AggregatedHttpObject.content()will return a pooled object, and the caller must ensure to release it. If you don't know what this means, useaggregate().The pooled
AggregatedHttpResponseis not cached. So it is NOT allowed to access theAggregatedHttpResponsefrom this method after the first aggregation.HttpResponse response = ...; AggregatedHttpResponse aggregated = response.aggregateWithPooledObjects(executor, alloc).join(); // An `IllegalStateException` will be raised. response.aggregateWithPooledObjects(executor, alloc).join(); -
toDuplicator
Description copied from interface:StreamMessageReturns a newStreamMessageDuplicatorthat duplicates thisStreamMessageinto one or moreStreamMessages, which publish the same elements. Note that you cannot subscribe to thisStreamMessageanymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()from the returnedStreamMessageDuplicator.- Specified by:
toDuplicatorin interfaceStreamMessage<HttpObject>
-
toDuplicator
Description copied from interface:StreamMessageReturns a newStreamMessageDuplicatorthat duplicates thisStreamMessageinto one or moreStreamMessages, which publish the same elements. Note that you cannot subscribe to thisStreamMessageanymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()from the returnedStreamMessageDuplicator.- Specified by:
toDuplicatorin interfaceStreamMessage<HttpObject>- Parameters:
executor- the executor to duplicate
-
toDuplicator
Description copied from interface:HttpMessageReturns a newStreamMessageDuplicatorthat duplicates thisHttpMessageinto one or moreHttpMessages, which publish the same elements. Note that you cannot subscribe to thisHttpMessageanymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()from the returnedStreamMessageDuplicator.- Specified by:
toDuplicatorin interfaceHttpMessage- Parameters:
maxResponseLength- the maximum content length that the duplicator can hold in its buffer.ContentTooLargeExceptionis raised if the length of the bufferedHttpDatais greater than this value.
-
toDuplicator
Description copied from interface:HttpMessageReturns a newStreamMessageDuplicatorthat duplicates thisHttpMessageinto one or moreHttpMessages, which publish the same elements. Note that you cannot subscribe to thisHttpMessageanymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()from the returnedStreamMessageDuplicator.- Specified by:
toDuplicatorin interfaceHttpMessage- Parameters:
executor- the executor to duplicatemaxResponseLength- the maximum content length that the duplicator can hold in its buffer.ContentTooLargeExceptionis raised if the length of the bufferedHttpDatais greater than this value.
-
split
Returns a newSplitHttpResponsewhich splits a stream ofHttpObjects intoHttpHeadersandHttpData.SplitHttpResponse.headers()will be completed before publishing the firstHttpData.SplitHttpMessage.trailers()might not complete until the entire response body is consumed completely. -
split
Returns a newSplitHttpResponsewhich splits a stream ofHttpObjects intoHttpHeadersandHttpData.SplitHttpResponse.headers()will be completed before publishing the firstHttpData.SplitHttpMessage.trailers()might not complete until the entire response body is consumed completely. -
mapInformational
default HttpResponse mapInformational(Function<? super ResponseHeaders, ? extends ResponseHeaders> function) -
mapHeaders
default HttpResponse mapHeaders(Function<? super ResponseHeaders, ? extends ResponseHeaders> function) Transforms the non-informationalResponseHeadersemitted byHttpResponseby applying the specifiedFunction.For example:
HttpResponse response = HttpResponse.of("OK"); HttpResponse transformed = response.mapHeaders(headers -> { return headers.withMutations(builder -> { builder.set(HttpHeaderNames.USER_AGENT, "my-server"); }); }); assert transformed.aggregate().join().headers() .get(HttpHeaderNames.USER_AGENT).equals("my-server"); -
mapData
Transforms theHttpDatas emitted by thisHttpResponseby applying the specifiedFunction.For example:
HttpResponse response = HttpResponse.of("data1,data2"); HttpResponse transformed = response.mapData(data -> { return HttpData.ofUtf8(data.toStringUtf8().replaceAll(",", "\n")); }); assert transformed.aggregate().join().contentUtf8().equals("data1\ndata2");- Specified by:
mapDatain interfaceHttpMessage
-
mapTrailers
Transforms the trailers emitted by thisHttpResponseby applying the specifiedFunction.For example:
HttpResponse response = HttpResponse.of("data"); HttpResponse transformed = response.mapTrailers(trailers -> { return trailers.withMutations(builder -> builder.add("trailer1", "foo")); }); assert transformed.aggregate().join().trailers().get("trailer1").equals("foo");- Specified by:
mapTrailersin interfaceHttpMessage
-
mapError
Transforms an error emitted by thisHttpResponseby applying the specifiedFunction.For example:
HttpResponse response = HttpResponse.ofFailure(new IllegalStateException("Something went wrong.")); HttpResponse transformed = response.mapError(cause -> { if (cause instanceof IllegalStateException) { return new MyDomainException(cause); } else { return cause; } });- Specified by:
mapErrorin interfaceStreamMessage<HttpObject>
-
peekHeaders
Applies the specifiedConsumerto the non-informationalResponseHeadersemitted by thisHttpResponse.For example:
HttpResponse response = HttpResponse.of(ResponseHeaders.of(HttpStatus.OK)); HttpResponse peeked = response.peekHeaders(headers -> { assert headers.status() == HttpStatus.OK; }); -
peekData
Applies the specifiedConsumerto theHttpDatas emitted by thisHttpResponse.For example:
HttpResponse response = HttpResponse.of("data1,data2"); HttpResponse peeked = response.peekData(data -> { assert data.toStringUtf8().equals("data1,data2"); });- Specified by:
peekDatain interfaceHttpMessage
-
peekTrailers
Applies the specifiedConsumerto the trailers emitted by thisHttpResponse.For example:
HttpResponse response = HttpResponse.of(ResponseHeaders.of(HttpStatus.OK), HttpData.ofUtf8("..."), HttpHeaders.of("trailer", "foo")); HttpResponse peeked = response.peekTrailers(trailers -> { assert trailers.get("trailer").equals("foo"); });- Specified by:
peekTrailersin interfaceHttpMessage
-
peekError
Applies the specifiedConsumerto an error emitted by thisHttpResponse.For example:
HttpResponse response = HttpResponse.ofFailure(new IllegalStateException("Something went wrong.")); HttpResponse peeked = response.peekError(cause -> { assert cause instanceof IllegalStateException; });- Specified by:
peekErrorin interfaceStreamMessage<HttpObject>
-
recover
Recovers a failedHttpResponseby switching to a returned fallbackHttpResponsewhen any error occurs before aResponseHeadersis written. Note that the failedHttpResponsecannot be recovered from an error if aResponseHeaderswas written already.Example:
HttpResponse response = HttpResponse.ofFailure(new IllegalStateException("Oops...")); // The failed HttpResponse will be recovered by the fallback function. HttpResponse recovered = response.recover(cause -> HttpResponse.of("Fallback")); assert recovered.aggregate().join().contentUtf8().equals("Fallback"); // As HTTP headers and body were written already before an error occurred, // the fallback function could not be applied for the failed HttpResponse. HttpResponseWriter response = HttpResponse.streaming(); response.write(ResponseHeaders.of(HttpStatus.OK)); response.write(HttpData.ofUtf8("Hello")); response.close(new IllegalStateException("Oops...")); HttpResponse notRecovered = response.recover(cause -> HttpResponse.of("Fallback")); // The IllegalStateException will be raised even though a fallback function was added. notRecovered.aggregate().join(); -
recover
@UnstableApi default <T extends Throwable> HttpResponse recover(Class<T> causeClass, Function<? super T, ? extends HttpResponse> function) Recovers a failedHttpResponseby switching to a returned fallbackHttpResponsewhen the thrownThrowableis the same type or a subtype of the specifiedcauseClass.Example:
HttpResponse response = HttpResponse.ofFailure(new IllegalStateException("Oops...")); // The failed HttpResponse will be recovered by the fallback function. HttpResponse recovered = response.recover(IllegalStateException.class, cause -> HttpResponse.of("Fallback")); assert recovered.aggregate().join().contentUtf8().equals("Fallback"); // As HTTP headers and body were written already before an error occurred, // the fallback function could not be applied for the failed HttpResponse. HttpResponseWriter response = HttpResponse.streaming(); response.write(ResponseHeaders.of(HttpStatus.OK)); response.write(HttpData.ofUtf8("Hello")); response.close(new IllegalStateException("Oops...")); HttpResponse notRecovered = response.recover(IllegalStateException.class, cause -> HttpResponse.of("Fallback")); // The IllegalStateException will be raised even though a fallback function was added. notRecovered.aggregate().join(); HttpResponse response = HttpResponse.ofFailure(new IllegalStateException("Oops...")); // Use the shortcut recover method as a chain. HttpResponse recoverChain = response.recover(RuntimeException.class, cause -> { final IllegalArgumentException ex = new IllegalArgumentException("Oops2..."); // If a failed response is returned from the first chain return HttpResponse.ofFailure(ex); }) // If the shortcut exception type is correct, catch and recover in the second chain. .recover(IllegalArgumentException.class, cause -> HttpResponse.of("fallback")); recoverChain.aggregate().join(); HttpResponse response = HttpResponse.ofFailure(new IllegalStateException("Oops...")); // If the exception type does not match HttpResponse mismatchRecovered = response.recover(IllegalArgumentException.class, cause -> HttpResponse.of("Fallback")); // In this case, CompletionException is thrown. (can't recover exception) mismatchRecovered.aggregate().join(); -
subscribeOn
Description copied from interface:StreamMessageCallsStreamMessage.subscribe(Subscriber, EventExecutor)to the upstreamStreamMessageusing the specifiedEventExecutorand relays the stream transparently downstream. This may be useful if one would like to hide anEventExecutorfrom an upstreamPublisher.For example:
Subscriber<Integer> mySubscriber = null; StreamMessage<Integer> upstream = ...; // publisher callbacks are invoked by eventLoop1 upstream.subscribeOn(eventLoop1) .subscribe(mySubscriber, eventLoop2); // mySubscriber callbacks are invoked with eventLoop2- Specified by:
subscribeOnin interfaceStreamMessage<HttpObject>
-
aggregate(AggregationOptions)withAggregationOptions.usePooledObjects(ByteBufAllocator).