Package com.linecorp.armeria.common
Interface HttpRequest
-
- All Superinterfaces:
org.reactivestreams.Publisher<HttpObject>
,Request
,StreamMessage<HttpObject>
- All Known Subinterfaces:
HttpRequestWriter
- All Known Implementing Classes:
DefaultHttpRequest
public interface HttpRequest extends Request, StreamMessage<HttpObject>
A streamed HTTP/2Request
.Note: The initial
RequestHeaders
is not signaled toSubscriber
s. It is readily available viaheaders()
.
-
-
Method Summary
Modifier and Type Method Description default CompletableFuture<AggregatedHttpRequest>
aggregate()
Aggregates this request.default CompletableFuture<AggregatedHttpRequest>
aggregate(EventExecutor executor)
Aggregates this request.default CompletableFuture<AggregatedHttpRequest>
aggregateWithPooledObjects(ByteBufAllocator alloc)
Aggregates this request.default CompletableFuture<AggregatedHttpRequest>
aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc)
Aggregates this request.default String
authority()
Returns the authority of this request.default MediaType
contentType()
Returns the value of the'content-type'
header.RequestHeaders
headers()
Returns the initial HTTP/2 headers of this request.default HttpMethod
method()
Returns the method of this request.static HttpRequest
of(AggregatedHttpRequest request)
Deprecated.static HttpRequest
of(HttpMethod method, String path)
Creates a new HTTP request with empty content and closes the stream.static HttpRequest
of(HttpMethod method, String path, MediaType mediaType, byte[] content)
Creates a new HTTP request and closes the stream.static HttpRequest
of(HttpMethod method, String path, MediaType mediaType, HttpData content)
Creates a new HTTP request and closes the stream.static HttpRequest
of(HttpMethod method, String path, MediaType mediaType, HttpData content, HttpHeaders trailers)
Creates a new HTTP request and closes the stream.static HttpRequest
of(HttpMethod method, String path, MediaType mediaType, CharSequence content)
Creates a new HTTP request and closes the stream.static HttpRequest
of(HttpMethod method, String path, MediaType mediaType, String content)
Creates a new HTTP request and closes the stream.static HttpRequest
of(HttpMethod method, String path, MediaType mediaType, String format, Object... args)
Creates a new HTTP request and closes the stream.static HttpRequest
of(HttpRequest request, RequestHeaders newHeaders)
Deprecated.static HttpRequest
of(RequestHeaders headers)
Creates a newHttpRequest
with empty content and closes the stream.static HttpRequest
of(RequestHeaders headers, HttpData content)
Creates a newHttpRequest
and closes the stream.static HttpRequest
of(RequestHeaders headers, HttpData... contents)
Creates a newHttpRequest
that publishes the givenHttpObject
s and closes the stream.static HttpRequest
of(RequestHeaders headers, HttpData content, HttpHeaders trailers)
Creates a newHttpRequest
and closes the stream.static HttpRequest
of(RequestHeaders headers, org.reactivestreams.Publisher<? extends HttpObject> publisher)
Creates a new instance from an existingRequestHeaders
andPublisher
.default String
path()
Returns the path of this request.default String
scheme()
Returns the scheme of this request.static HttpRequestWriter
streaming(HttpMethod method, String path)
Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObject
with the initialRequestHeaders
of the specifiedHttpMethod
andpath
.static HttpRequestWriter
streaming(RequestHeaders headers)
Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObject
with the specified initialRequestHeaders
.default URI
uri()
Returns the URI of this request.default HttpRequest
withHeaders(RequestHeaders newHeaders)
Returns a newHttpRequest
derived from thisHttpRequest
by replacing itsRequestHeaders
with the specifiednewHeaders
.default HttpRequest
withHeaders(RequestHeadersBuilder newHeadersBuilder)
Returns a newHttpRequest
derived from thisHttpRequest
by replacing itsRequestHeaders
with what's built from the specifiednewHeadersBuilder
.-
Methods inherited from interface com.linecorp.armeria.common.stream.StreamMessage
abort, abort, closeFuture, completionFuture, drainAll, drainAll, drainAll, drainAll, drainAll, drainAll, isComplete, isEmpty, isOpen, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe
-
-
-
-
Method Detail
-
streaming
static HttpRequestWriter streaming(HttpMethod method, String path)
Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObject
with the initialRequestHeaders
of the specifiedHttpMethod
andpath
.
-
streaming
static HttpRequestWriter streaming(RequestHeaders headers)
Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObject
with the specified initialRequestHeaders
.
-
of
static HttpRequest of(HttpMethod method, String path)
Creates a new HTTP request with empty content and closes the stream.- Parameters:
method
- the HTTP method of the requestpath
- the path of the request
-
of
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, CharSequence content)
Creates a new HTTP request and closes the stream.- Parameters:
method
- the HTTP method of the requestpath
- the path of the requestmediaType
- theMediaType
of the request contentcontent
- the content of the request
-
of
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, String content)
Creates a new HTTP request and closes the stream.- Parameters:
method
- the HTTP method of the requestpath
- the path of the requestmediaType
- theMediaType
of the request contentcontent
- the content of the request
-
of
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, String format, Object... args)
Creates a new HTTP request and closes the stream. The content of the request is formatted byString.format(Locale, String, Object...)
with English locale.- Parameters:
method
- the HTTP method of the requestpath
- the path of the requestmediaType
- theMediaType
of the request contentformat
- the format string of the request contentargs
- the arguments referenced by the format specifiers in the format string
-
of
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, byte[] content)
Creates a new HTTP request and closes the stream. Thecontent
will be wrapped usingHttpData.wrap(byte[])
, so any changes made tocontent
will be reflected in the request.- Parameters:
method
- the HTTP method of the requestpath
- the path of the requestmediaType
- theMediaType
of the request contentcontent
- the content of the request
-
of
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, HttpData content)
Creates a new HTTP request and closes the stream.- Parameters:
method
- the HTTP method of the requestpath
- the path of the requestmediaType
- theMediaType
of the request contentcontent
- the content of the request
-
of
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, HttpData content, HttpHeaders trailers)
Creates a new HTTP request and closes the stream.- Parameters:
method
- the HTTP method of the requestpath
- the path of the requestmediaType
- theMediaType
of the request contentcontent
- the content of the requesttrailers
- the HTTP trailers
-
of
static HttpRequest of(RequestHeaders headers)
Creates a newHttpRequest
with empty content and closes the stream.
-
of
static HttpRequest of(RequestHeaders headers, HttpData content)
Creates a newHttpRequest
and closes the stream.
-
of
static HttpRequest of(RequestHeaders headers, HttpData content, HttpHeaders trailers)
Creates a newHttpRequest
and closes the stream.- Throws:
IllegalStateException
- if the headers are malformed.
-
of
static HttpRequest of(RequestHeaders headers, HttpData... contents)
Creates a newHttpRequest
that publishes the givenHttpObject
s and closes the stream.
-
of
@Deprecated static HttpRequest of(AggregatedHttpRequest request)
Deprecated.Converts theAggregatedHttpRequest
into a new completeHttpRequest
.
-
of
static HttpRequest of(RequestHeaders headers, org.reactivestreams.Publisher<? extends HttpObject> publisher)
Creates a new instance from an existingRequestHeaders
andPublisher
.
-
of
@Deprecated static HttpRequest of(HttpRequest request, RequestHeaders newHeaders)
Deprecated.Returns a newHttpRequest
derived from an existingHttpRequest
by replacing itsRequestHeaders
with the specifiednewHeaders
. Note that the content stream and trailers of the specifiedHttpRequest
is not duplicated, which means you can subscribe to only one of the twoHttpRequest
s.If you are using this method for intercepting an
HttpRequest
in a decorator, make sure to updateRequestContext.request()
withRequestContext.updateRequest(HttpRequest)
, e.g.> public class MyService extends SimpleDecoratingHttpService { > @Override > public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) { > // Create a new request with an additional header. > final HttpRequest newReq = > HttpRequest.of(req, > req.headers().toBuilder() > .set("x-custom-header", "value") > .build()); > > // Update the ctx.request. > ctx.updateRequest(newReq); > > // Delegate the new request with the updated context. > return delegate().serve(ctx, newReq); > } > }
-
headers
RequestHeaders headers()
Returns the initial HTTP/2 headers of this request.
-
uri
default URI uri()
Returns the URI of this request. This method is a shortcut ofheaders().uri()
.
-
scheme
@Nullable default String scheme()
Returns the scheme of this request. This method is a shortcut ofheaders().scheme()
.
-
method
default HttpMethod method()
Returns the method of this request. This method is a shortcut ofheaders().method()
.
-
path
default String path()
Returns the path of this request. This method is a shortcut ofheaders().path()
.
-
authority
@Nullable default String authority()
Returns the authority of this request. This method is a shortcut ofheaders().authority()
.
-
contentType
@Nullable default MediaType contentType()
Returns the value of the'content-type'
header.- Returns:
- the valid header value if present.
null
otherwise.
-
withHeaders
default HttpRequest withHeaders(RequestHeaders newHeaders)
Returns a newHttpRequest
derived from thisHttpRequest
by replacing itsRequestHeaders
with the specifiednewHeaders
. Note that the content stream and trailers of thisHttpRequest
is not duplicated, which means you can subscribe to only one of the twoHttpRequest
s.If you are using this method for intercepting an
HttpRequest
in a decorator, make sure to updateRequestContext.request()
withRequestContext.updateRequest(HttpRequest)
, e.g.> public class MyService extends SimpleDecoratingHttpService { > @Override > public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) { > // Create a new request with an additional header. > final HttpRequest newReq = > req.withHeaders(req.headers().toBuilder() > .set("x-custom-header", "value") > .build()); > > // Update the ctx.request. > ctx.updateRequest(newReq); > > // Delegate the new request with the updated context. > return delegate().serve(ctx, newReq); > } > }
-
withHeaders
default HttpRequest withHeaders(RequestHeadersBuilder newHeadersBuilder)
Returns a newHttpRequest
derived from thisHttpRequest
by replacing itsRequestHeaders
with what's built from the specifiednewHeadersBuilder
. Note that the content stream and trailers of thisHttpRequest
is not duplicated, which means you can subscribe to only one of the twoHttpRequest
s.If you are using this method for intercepting an
HttpRequest
in a decorator, make sure to updateRequestContext.request()
withRequestContext.updateRequest(HttpRequest)
, e.g.> public class MyService extends SimpleDecoratingHttpService { > @Override > public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) { > // Create a new request with an additional header. > final HttpRequest newReq = > req.withHeaders(req.headers().toBuilder() > .set("x-custom-header", "value")); > > // Update the ctx.request. > ctx.updateRequest(newReq); > > // Delegate the new request with the updated context. > return delegate().serve(ctx, newReq); > } > }
-
aggregate
default CompletableFuture<AggregatedHttpRequest> aggregate()
Aggregates this request. The returnedCompletableFuture
will be notified when the content and the trailers of the request is received fully.
-
aggregate
default CompletableFuture<AggregatedHttpRequest> aggregate(EventExecutor executor)
Aggregates this request. The returnedCompletableFuture
will be notified when the content and the trailers of the request is received fully.
-
aggregateWithPooledObjects
default CompletableFuture<AggregatedHttpRequest> aggregateWithPooledObjects(ByteBufAllocator alloc)
Aggregates this request. 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()
.
-
aggregateWithPooledObjects
default CompletableFuture<AggregatedHttpRequest> aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc)
Aggregates this request. 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()
.
-
-