Package com.linecorp.armeria.common
Interface HttpResponse
- All Superinterfaces:
org.reactivestreams.Publisher<HttpObject>
,Response
,StreamMessage<HttpObject>
- All Known Subinterfaces:
HttpResponseWriter
,PooledHttpResponse
- All Known Implementing Classes:
FilteredHttpResponse
public interface HttpResponse extends Response, StreamMessage<HttpObject>
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.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(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 HttpResponseWriter
streaming()
Creates a new HTTP response that can stream an arbitrary number ofHttpObject
to the client.default HttpResponseDuplicator
toDuplicator()
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
s, which publish the same elements.default HttpResponseDuplicator
toDuplicator(long maxResponseLength)
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
s, which publish the same elements.default HttpResponseDuplicator
toDuplicator(EventExecutor executor)
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
s, which publish the same elements.default HttpResponseDuplicator
toDuplicator(EventExecutor executor, long maxResponseLength)
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
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.stream.StreamMessage
abort, abort, defaultSubscriberExecutor, isComplete, isEmpty, isOpen, 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
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
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
. -
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. -
toDuplicator
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
s, which publish the same elements. Note that you cannot subscribe to thisHttpResponse
anymore after you call this method. To subscribe, callHttpResponseDuplicator.duplicate()
from the returnedHttpResponseDuplicator
.- Specified by:
toDuplicator
in interfaceStreamMessage<HttpObject>
-
toDuplicator
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
s, which publish the same elements. Note that you cannot subscribe to thisHttpResponse
anymore after you call this method. To subscribe, callHttpResponseDuplicator.duplicate()
from the returnedHttpResponseDuplicator
.- Specified by:
toDuplicator
in interfaceStreamMessage<HttpObject>
- Parameters:
executor
- the executor to duplicate
-
toDuplicator
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
s, which publish the same elements. Note that you cannot subscribe to thisHttpResponse
anymore after you call this method. To subscribe, callHttpResponseDuplicator.duplicate()
from the returnedHttpResponseDuplicator
.- Parameters:
maxResponseLength
- the maximum response length that the duplicator can hold in its buffer.ContentTooLargeException
is raised if the length of the bufferedHttpData
is greater than this value.
-
toDuplicator
Returns a newHttpResponseDuplicator
that duplicates thisHttpResponse
into one or moreHttpResponse
s, which publish the same elements. Note that you cannot subscribe to thisHttpResponse
anymore after you call this method. To subscribe, callHttpResponseDuplicator.duplicate()
from the returnedHttpResponseDuplicator
.- Parameters:
executor
- the executor to duplicatemaxResponseLength
- the maximum response length that the duplicator can hold in its buffer.ContentTooLargeException
is raised if the length of the bufferedHttpData
is greater than this value.
-