Package com.linecorp.armeria.common
Interface HttpResponse
- All Superinterfaces:
HttpMessage
,org.reactivestreams.Publisher<HttpObject>
,Response
,StreamMessage<HttpObject>
- All Known Subinterfaces:
HttpResponseWriter
- All Known Implementing Classes:
FilteredHttpResponse
public interface HttpResponse extends Response, HttpMessage
A streamed HTTP/2
Response
.-
Method Summary
Modifier and Type Method Description default CompletableFuture<AggregatedHttpResponse>
aggregate()
Aggregates this response.default CompletableFuture<AggregatedHttpResponse>
aggregate(EventExecutor executor)
Aggregates this response.default CompletableFuture<AggregatedHttpResponse>
aggregateWithPooledObjects(ByteBufAllocator alloc)
(Advanced users only) Aggregates this response.default CompletableFuture<AggregatedHttpResponse>
aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc)
Aggregates this response.default <T> StreamMessage<T>
decode(HttpDecoder<T> decoder, ByteBufAllocator alloc, Function<? super HttpData,? extends ByteBuf> byteBufConverter)
Creates a decodedStreamMessage
which is decoded from a stream ofHttpObject
s using the specifiedHttpDecoder
andByteBufAllocator
andbyteBufConverter
.static HttpResponse
delayed(AggregatedHttpResponse response, Duration delay)
Creates a new HTTP response that delegates to the providedAggregatedHttpResponse
, beginning publishing afterdelay
has passed from a randomScheduledExecutorService
.static HttpResponse
delayed(AggregatedHttpResponse response, Duration delay, ScheduledExecutorService executor)
Creates a new HTTP response that delegates to the providedAggregatedHttpResponse
, beginning publishing afterdelay
has passed from the providedScheduledExecutorService
.static HttpResponse
delayed(HttpResponse response, Duration delay)
Creates a new HTTP response that delegates to the providedHttpResponse
, beginning publishing afterdelay
has passed from a randomScheduledExecutorService
.static HttpResponse
delayed(HttpResponse response, Duration delay, ScheduledExecutorService executor)
Creates a new HTTP response that delegates to the providedHttpResponse
, beginning publishing afterdelay
has passed from the providedScheduledExecutorService
.static HttpResponse
from(CompletionStage<? extends HttpResponse> stage)
Creates a new HTTP response that delegates to theHttpResponse
produced by the specifiedCompletionStage
.static HttpResponse
from(CompletionStage<? extends HttpResponse> stage, EventExecutor subscriberExecutor)
Creates a new HTTP response that delegates to theHttpResponse
produced by the specifiedCompletionStage
.static HttpResponse
of(int statusCode)
Creates a new HTTP response of the specifiedstatusCode
.static HttpResponse
of(HttpObject... objs)
Creates a new HTTP response of the specified objects.static HttpResponse
of(HttpStatus status)
Creates a new HTTP response of the specifiedHttpStatus
.static HttpResponse
of(HttpStatus status, MediaType mediaType, byte[] content)
Creates a new HTTP response of the specifiedHttpStatus
.static HttpResponse
of(HttpStatus status, MediaType mediaType, HttpData content)
Creates a new HTTP response of the specifiedHttpStatus
.static HttpResponse
of(HttpStatus status, MediaType mediaType, HttpData content, HttpHeaders trailers)
Creates a new HTTP response of the specifiedHttpStatus
.static HttpResponse
of(HttpStatus status, MediaType mediaType, CharSequence content)
Creates a new HTTP response of the specifiedHttpStatus
.static HttpResponse
of(HttpStatus status, MediaType mediaType, String content)
Creates a new HTTP response of the specifiedHttpStatus
.static HttpResponse
of(HttpStatus status, MediaType mediaType, String format, Object... args)
Creates a new HTTP response of the specifiedHttpStatus
.static HttpResponse
of(MediaType mediaType, String content)
Creates a new HTTP response of OK status with the content.static HttpResponse
of(MediaType mediaType, String format, Object... args)
Creates a new HTTP response of OK status with the content.static HttpResponse
of(ResponseHeaders headers)
Creates a new HTTP response of the specified headers.static HttpResponse
of(ResponseHeaders headers, HttpData content)
Creates a new HTTP response of the specified headers and content.static HttpResponse
of(ResponseHeaders headers, HttpData content, HttpHeaders trailers)
Creates a new HTTP response of the specified objects.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
.static HttpResponse
of(String content)
Creates a new HTTP response of OK status with the content as UTF_8.static HttpResponse
of(String format, Object... args)
Creates a new HTTP response of OK status with the content as UTF_8.static HttpResponse
of(org.reactivestreams.Publisher<? extends HttpObject> publisher)
Creates a new HTTP response whose stream is produced from an existingPublisher
.static HttpResponse
ofFailure(Throwable cause)
Creates a new failed HTTP response.static HttpResponse
ofRedirect(HttpStatus redirectStatus, String location)
Creates a new HTTP response of the redirect to specific location.static HttpResponse
ofRedirect(HttpStatus redirectStatus, String format, Object... args)
Creates a new HTTP response of the redirect to specific location using string format.static HttpResponse
ofRedirect(String location)
Creates a new HTTP response of the temporary redirect to specific location.static HttpResponse
ofRedirect(String format, Object... args)
Creates a new HTTP response of the temporary redirect to specific location using string format.default SplitHttpResponse
split()
default SplitHttpResponse
split(EventExecutor executor)
static HttpResponseWriter
streaming()
Creates a new HTTP response that can stream an arbitrary number ofHttpObject
to the client.default HttpResponseDuplicator
toDuplicator()
Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements.default HttpResponseDuplicator
toDuplicator(long maxResponseLength)
Returns a newStreamMessageDuplicator
that duplicates thisHttpMessage
into one or moreHttpMessage
s, which publish the same elements.default HttpResponseDuplicator
toDuplicator(EventExecutor executor)
Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements.default HttpResponseDuplicator
toDuplicator(EventExecutor executor, long maxResponseLength)
Returns a newStreamMessageDuplicator
that duplicates thisHttpMessage
into one or moreHttpMessage
s, which publish the same elements.CompletableFuture<Void>
whenComplete()
Returns aCompletableFuture
which completes when 1) the response stream has been closed (theStreamMessage
has been completed) or 2) the result value is set (theCompletionStage
has completed.)Methods inherited from interface com.linecorp.armeria.common.HttpMessage
decode, decode
Methods inherited from interface com.linecorp.armeria.common.stream.StreamMessage
abort, abort, defaultSubscriberExecutor, demand, filter, isComplete, isEmpty, isOpen, map, subscribe, subscribe, subscribe, subscribe
-
Method Details
-
streaming
Creates a new HTTP response that can stream an arbitrary number ofHttpObject
to the client. The first object written must be of typeResponseHeaders
. -
from
Creates a new HTTP response that delegates to theHttpResponse
produced by the specifiedCompletionStage
. If the specifiedCompletionStage
fails, the returned response will be closed with the same cause as well.- Parameters:
stage
- theCompletionStage
which will produce the actualHttpResponse
-
from
static HttpResponse from(CompletionStage<? extends HttpResponse> stage, EventExecutor subscriberExecutor)Creates a new HTTP response that delegates to theHttpResponse
produced by the specifiedCompletionStage
. If the specifiedCompletionStage
fails, the returned response will be closed with the same cause as well.- Parameters:
stage
- theCompletionStage
which will produce the actualHttpResponse
subscriberExecutor
- theEventExecutor
which will be used when a user subscribes the returnedHttpResponse
usingStreamMessage.subscribe(Subscriber)
orStreamMessage.subscribe(Subscriber, SubscriptionOption...)
.
-
delayed
Creates a new HTTP response that delegates to the providedAggregatedHttpResponse
, beginning publishing afterdelay
has 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 afterdelay
has passed from the providedScheduledExecutorService
. -
delayed
Creates a new HTTP response that delegates to the providedHttpResponse
, beginning publishing afterdelay
has 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 afterdelay
has passed from the providedScheduledExecutorService
. -
of
Creates a new HTTP response of the specifiedstatusCode
.- Throws:
IllegalArgumentException
- if the specifiedstatusCode
is informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus
.- Throws:
IllegalArgumentException
- if the specifiedHttpStatus
is informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus
.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response- Throws:
IllegalArgumentException
- if the specifiedHttpStatus
is informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus
.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response- Throws:
IllegalArgumentException
- if the specifiedHttpStatus
is 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
- theMediaType
of 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
- theMediaType
of 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
- theMediaType
of 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 specifiedHttpStatus
is informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus
. Thecontent
will be wrapped usingHttpData.wrap(byte[])
, so any changes made tocontent
will be reflected in the response.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response- Throws:
IllegalArgumentException
- if the specifiedHttpStatus
is informational.
-
of
Creates a new HTTP response of the specifiedHttpStatus
.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response- Throws:
IllegalArgumentException
- if the specifiedHttpStatus
is informational.
-
of
static HttpResponse of(HttpStatus status, MediaType mediaType, HttpData content, HttpHeaders trailers)Creates a new HTTP response of the specifiedHttpStatus
.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the responsetrailers
- the HTTP trailers- Throws:
IllegalArgumentException
- if the specifiedHttpStatus
is informational.
-
of
Creates a new HTTP response of the specified headers.- Throws:
IllegalArgumentException
- if the status of the specifiedResponseHeaders
is informational.
-
of
Creates a new HTTP response of the specified headers and content.- Throws:
IllegalArgumentException
- if the status of the specifiedResponseHeaders
is informational.
-
of
Creates a new HTTP response of the specified objects.- Throws:
IllegalArgumentException
- if the status of the specifiedResponseHeaders
is informational.
-
of
Creates a new HTTP response of the specified objects. -
of
Creates a new HTTP response whose stream is produced from an existingPublisher
. -
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
. -
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. -
whenComplete
CompletableFuture<Void> whenComplete()Description copied from interface:Response
Returns aCompletableFuture
which completes when 1) the response stream has been closed (theStreamMessage
has been completed) or 2) the result value is set (theCompletionStage
has completed.)- Specified by:
whenComplete
in interfaceResponse
- Specified by:
whenComplete
in interfaceStreamMessage<HttpObject>
-
aggregate
Aggregates this response. The returnedCompletableFuture
will be notified when the content and the trailers of the response are received fully. -
aggregate
Aggregates this response. The returnedCompletableFuture
will be notified when the content and the trailers of the response are received fully. -
aggregateWithPooledObjects
@UnstableApi default CompletableFuture<AggregatedHttpResponse> aggregateWithPooledObjects(ByteBufAllocator alloc)(Advanced users only) Aggregates this response. The returnedCompletableFuture
will 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()
.- See Also:
PooledObjects
-
aggregateWithPooledObjects
default CompletableFuture<AggregatedHttpResponse> aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc)Aggregates this response. The returnedCompletableFuture
will be notified when the content and the trailers of the request 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()
. -
toDuplicator
Description copied from interface:StreamMessage
Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements. Note that you cannot subscribe to thisStreamMessage
anymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()
from the returnedStreamMessageDuplicator
.- Specified by:
toDuplicator
in interfaceStreamMessage<HttpObject>
-
toDuplicator
Description copied from interface:StreamMessage
Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements. Note that you cannot subscribe to thisStreamMessage
anymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()
from the returnedStreamMessageDuplicator
.- Specified by:
toDuplicator
in interfaceStreamMessage<HttpObject>
- Parameters:
executor
- the executor to duplicate
-
toDuplicator
Description copied from interface:HttpMessage
Returns a newStreamMessageDuplicator
that duplicates thisHttpMessage
into one or moreHttpMessage
s, which publish the same elements. Note that you cannot subscribe to thisHttpMessage
anymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()
from the returnedStreamMessageDuplicator
.- Specified by:
toDuplicator
in interfaceHttpMessage
- Parameters:
maxResponseLength
- the maximum content length that the duplicator can hold in its buffer.ContentTooLargeException
is raised if the length of the bufferedHttpData
is greater than this value.
-
toDuplicator
Description copied from interface:HttpMessage
Returns a newStreamMessageDuplicator
that duplicates thisHttpMessage
into one or moreHttpMessage
s, which publish the same elements. Note that you cannot subscribe to thisHttpMessage
anymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()
from the returnedStreamMessageDuplicator
.- Specified by:
toDuplicator
in interfaceHttpMessage
- Parameters:
executor
- the executor to duplicatemaxResponseLength
- the maximum content length that the duplicator can hold in its buffer.ContentTooLargeException
is raised if the length of the bufferedHttpData
is greater than this value.
-
split
Returns a newSplitHttpResponse
which splits a stream ofHttpObject
s intoHttpHeaders
andHttpData
.SplitHttpResponse.headers()
will be completed before publishing the firstHttpData
.SplitHttpResponse.trailers()
might not complete until the entire response body is consumed completely. -
split
Returns a newSplitHttpResponse
which splits a stream ofHttpObject
s intoHttpHeaders
andHttpData
.SplitHttpResponse.headers()
will be completed before publishing the firstHttpData
.SplitHttpResponse.trailers()
might not complete until the entire response body is consumed completely. -
decode
default <T> StreamMessage<T> decode(HttpDecoder<T> decoder, ByteBufAllocator alloc, Function<? super HttpData,? extends ByteBuf> byteBufConverter)Description copied from interface:HttpMessage
Creates a decodedStreamMessage
which is decoded from a stream ofHttpObject
s using the specifiedHttpDecoder
andByteBufAllocator
andbyteBufConverter
.- Specified by:
decode
in interfaceHttpMessage
-