Package com.linecorp.armeria.common
Interface HttpResponse
-
- All Superinterfaces:
org.reactivestreams.Publisher<HttpObject>
,Response
,StreamMessage<HttpObject>
- All Known Subinterfaces:
HttpResponseWriter
- All Known Implementing Classes:
DefaultHttpResponse
,DeferredHttpResponse
,FilteredHttpResponse
public interface HttpResponse extends Response, StreamMessage<HttpObject>
A streamed HTTP/2Response
.
-
-
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)
Aggregates this response.default CompletableFuture<AggregatedHttpResponse>
aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc)
Aggregates this response.default CompletableFuture<Void>
closeFuture()
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.)CompletableFuture<Void>
completionFuture()
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.)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(AggregatedHttpResponse res)
Deprecated.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
ofFailed(Throwable cause)
Deprecated.UseofFailure(Throwable)
.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.
-
-
-
Method Detail
-
streaming
static HttpResponseWriter 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
static HttpResponse from(CompletionStage<? extends HttpResponse> stage)
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
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
.
-
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
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
.
-
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
static HttpResponse of(int statusCode)
Creates a new HTTP response of the specifiedstatusCode
.- Throws:
IllegalArgumentException
- if theHttpStatusClass
is informational (1xx).
-
of
static HttpResponse of(HttpStatus status)
Creates a new HTTP response of the specifiedHttpStatus
.- Throws:
IllegalArgumentException
- if theHttpStatusClass
is informational (1xx).
-
of
static HttpResponse of(HttpStatus status, MediaType mediaType, CharSequence content)
Creates a new HTTP response of the specifiedHttpStatus
.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response
-
of
static HttpResponse of(HttpStatus status, MediaType mediaType, String content)
Creates a new HTTP response of the specifiedHttpStatus
.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response
-
of
static HttpResponse of(String content)
Creates a new HTTP response of OK status with the content as UTF_8.- Parameters:
content
- the content of the response
-
of
static HttpResponse of(String format, Object... args)
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
static HttpResponse of(MediaType mediaType, String content)
Creates a new HTTP response of OK status with the content.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response
-
of
static HttpResponse of(MediaType mediaType, 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
static HttpResponse of(HttpStatus status, MediaType mediaType, 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
-
of
static HttpResponse of(HttpStatus status, MediaType mediaType, byte[] content)
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
-
of
static HttpResponse of(HttpStatus status, MediaType mediaType, HttpData content)
Creates a new HTTP response of the specifiedHttpStatus
.- Parameters:
mediaType
- theMediaType
of the response contentcontent
- the content of the response
-
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
-
of
static HttpResponse of(ResponseHeaders headers)
Creates a new HTTP response of the specified headers.
-
of
static HttpResponse of(ResponseHeaders headers, HttpData content)
Creates a new HTTP response of the specified headers and content.
-
of
static HttpResponse of(ResponseHeaders headers, HttpData content, HttpHeaders trailers)
Creates a new HTTP response of the specified objects.
-
of
static HttpResponse of(HttpObject... objs)
Creates a new HTTP response of the specified objects.
-
of
@Deprecated static HttpResponse of(AggregatedHttpResponse res)
Deprecated.Converts theAggregatedHttpResponse
into a new completeHttpResponse
.
-
of
static HttpResponse of(org.reactivestreams.Publisher<? extends HttpObject> publisher)
Creates a new HTTP response whose stream is produced from an existingPublisher
.
-
ofFailure
static HttpResponse ofFailure(Throwable cause)
Creates a new failed HTTP response.
-
ofFailed
@Deprecated static HttpResponse ofFailed(Throwable cause)
Deprecated.UseofFailure(Throwable)
.Creates a new failed HTTP response.
-
closeFuture
default CompletableFuture<Void> closeFuture()
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:
closeFuture
in interfaceResponse
- Specified by:
closeFuture
in interfaceStreamMessage<HttpObject>
-
completionFuture
CompletableFuture<Void> completionFuture()
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:
completionFuture
in interfaceResponse
- Specified by:
completionFuture
in interfaceStreamMessage<HttpObject>
-
aggregate
default CompletableFuture<AggregatedHttpResponse> aggregate()
Aggregates this response. The returnedCompletableFuture
will be notified when the content and the trailers of the response are received fully.
-
aggregate
default CompletableFuture<AggregatedHttpResponse> aggregate(EventExecutor executor)
Aggregates this response. The returnedCompletableFuture
will be notified when the content and the trailers of the response are received fully.
-
aggregateWithPooledObjects
default CompletableFuture<AggregatedHttpResponse> aggregateWithPooledObjects(ByteBufAllocator alloc)
Aggregates this response. The returnedCompletableFuture
will be notified when the content and the trailers of the response are received fully.AggregatedHttpMessage.content()
will return a pooled object, and the caller must ensure to release it. If you don't know what this means, useaggregate()
.
-
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.AggregatedHttpMessage.content()
will return a pooled object, and the caller must ensure to release it. If you don't know what this means, useaggregate()
.
-
-