Package com.linecorp.armeria.common
Interface HttpRequest
- All Superinterfaces:
HttpMessage,org.reactivestreams.Publisher<HttpObject>,Request,StreamMessage<HttpObject>
- All Known Subinterfaces:
HttpRequestWriter
- All Known Implementing Classes:
FilteredHttpRequest
public interface HttpRequest extends Request, HttpMessage
A streamed HTTP/2
Request.
Note: The initial RequestHeaders is not signaled to Subscribers. It is readily available
via headers().
-
Method Summary
Modifier and Type Method Description default List<Locale.LanguageRange>acceptLanguages()Returns a list ofLocale.LanguageRanges that are specified inHttpHeaderNames.ACCEPT_LANGUAGEin the order of client-side preferences.default CompletableFuture<AggregatedHttpRequest>aggregate()Aggregates this request.default CompletableFuture<AggregatedHttpRequest>aggregate(EventExecutor executor)Aggregates this request.default CompletableFuture<AggregatedHttpRequest>aggregateWithPooledObjects(ByteBufAllocator alloc)(Advanced users only) Aggregates this request.default CompletableFuture<AggregatedHttpRequest>aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc)Aggregates this request.default Stringauthority()Returns the authority of this request.static HttpRequestBuilderbuilder()Returns a newHttpRequestBuilder.default MediaTypecontentType()Returns the value of the'content-type'header.default <T> StreamMessage<T>decode(HttpDecoder<T> decoder, ByteBufAllocator alloc, Function<? super HttpData,? extends ByteBuf> byteBufConverter)Creates a decodedStreamMessagewhich is decoded from a stream ofHttpObjects using the specifiedHttpDecoderandByteBufAllocatorandbyteBufConverter.RequestHeadersheaders()Returns the initial HTTP/2 headers of this request.default HttpRequestmapData(Function<? super HttpData,? extends HttpData> function)default HttpRequestmapHeaders(Function<? super RequestHeaders,? extends RequestHeaders> function)default HttpRequestmapTrailers(Function<? super HttpHeaders,? extends HttpHeaders> function)default HttpMethodmethod()Returns the method of this request.static HttpRequestof(HttpMethod method, String path)Creates a new HTTP request with empty content and closes the stream.static HttpRequestof(HttpMethod method, String path, MediaType mediaType, byte[] content)Creates a new HTTP request and closes the stream.static HttpRequestof(HttpMethod method, String path, MediaType mediaType, HttpData content)Creates a new HTTP request and closes the stream.static HttpRequestof(HttpMethod method, String path, MediaType mediaType, HttpData content, HttpHeaders trailers)Creates a new HTTP request and closes the stream.static HttpRequestof(HttpMethod method, String path, MediaType mediaType, CharSequence content)Creates a new HTTP request and closes the stream.static HttpRequestof(HttpMethod method, String path, MediaType mediaType, String content)Creates a new HTTP request and closes the stream.static HttpRequestof(HttpMethod method, String path, MediaType mediaType, String format, Object... args)Creates a new HTTP request and closes the stream.static HttpRequestof(RequestHeaders headers)Creates a newHttpRequestwith empty content and closes the stream.static HttpRequestof(RequestHeaders headers, HttpData content)Creates a newHttpRequestand closes the stream.static HttpRequestof(RequestHeaders headers, HttpData... contents)Creates a newHttpRequestthat publishes the givenHttpObjects and closes the stream.static HttpRequestof(RequestHeaders headers, HttpData content, HttpHeaders trailers)Creates a newHttpRequestand closes the stream.static HttpRequestof(RequestHeaders headers, org.reactivestreams.Publisher<? extends HttpObject> publisher)Creates a new instance from an existingRequestHeadersandPublisher.default Stringpath()Returns the path of this request.default Stringscheme()Returns the scheme of this request.default LocaleselectLocale(Iterable<Locale> supportedLocales)Matches theLocales supported by the server to theHttpHeaderNames.ACCEPT_LANGUAGEand returning the best match according to client preference.default LocaleselectLocale(Locale... supportedLocales)Matches theLocales supported by the server to theHttpHeaderNames.ACCEPT_LANGUAGEand returning the best match according to client preference.static HttpRequestWriterstreaming(HttpMethod method, String path)Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObjectwith the initialRequestHeadersof the specifiedHttpMethodandpath.static HttpRequestWriterstreaming(RequestHeaders headers)Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObjectwith the specified initialRequestHeaders.default HttpRequestDuplicatortoDuplicator()Returns a newStreamMessageDuplicatorthat duplicates thisStreamMessageinto one or moreStreamMessages, which publish the same elements.default HttpRequestDuplicatortoDuplicator(long maxRequestLength)Returns a newStreamMessageDuplicatorthat duplicates thisHttpMessageinto one or moreHttpMessages, which publish the same elements.default HttpRequestDuplicatortoDuplicator(EventExecutor executor)Returns a newStreamMessageDuplicatorthat duplicates thisStreamMessageinto one or moreStreamMessages, which publish the same elements.default HttpRequestDuplicatortoDuplicator(EventExecutor executor, long maxRequestLength)Returns a newStreamMessageDuplicatorthat duplicates thisHttpMessageinto one or moreHttpMessages, which publish the same elements.default URIuri()Returns the URI of this request.default HttpRequestwithHeaders(RequestHeaders newHeaders)Returns a newHttpRequestderived from thisHttpRequestby replacing itsRequestHeaderswith the specifiednewHeaders.default HttpRequestwithHeaders(RequestHeadersBuilder newHeadersBuilder)Returns a newHttpRequestderived from thisHttpRequestby replacing itsRequestHeaderswith what's built from the specifiednewHeadersBuilder.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, defaultSubscriberExecutor, demand, filter, isComplete, isEmpty, isOpen, map, subscribe, subscribe, subscribe, subscribe, whenComplete
-
Method Details
-
streaming
Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObjectwith the initialRequestHeadersof the specifiedHttpMethodandpath. -
streaming
Creates a new HTTP request that can be used to stream an arbitrary number ofHttpObjectwith the specified initialRequestHeaders. -
of
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
Creates a new HTTP request and closes the stream.- Parameters:
method- the HTTP method of the requestpath- the path of the requestmediaType- theMediaTypeof the request contentcontent- the content of the request
-
of
Creates a new HTTP request and closes the stream.- Parameters:
method- the HTTP method of the requestpath- the path of the requestmediaType- theMediaTypeof the request contentcontent- the content of the request
-
of
@FormatMethod static HttpRequest of(HttpMethod method, String path, MediaType mediaType, @FormatString 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- theMediaTypeof the request contentformat- the format string of the request contentargs- the arguments referenced by the format specifiers in the format string
-
of
Creates a new HTTP request and closes the stream. Thecontentwill be wrapped usingHttpData.wrap(byte[]), so any changes made tocontentwill be reflected in the request.- Parameters:
method- the HTTP method of the requestpath- the path of the requestmediaType- theMediaTypeof the request contentcontent- the content of the request
-
of
Creates a new HTTP request and closes the stream.- Parameters:
method- the HTTP method of the requestpath- the path of the requestmediaType- theMediaTypeof 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- theMediaTypeof the request contentcontent- the content of the requesttrailers- the HTTP trailers
-
of
Creates a newHttpRequestwith empty content and closes the stream. -
of
Creates a newHttpRequestand closes the stream. -
of
Creates a newHttpRequestand closes the stream.- Throws:
IllegalStateException- if the headers are malformed.
-
of
Creates a newHttpRequestthat publishes the givenHttpObjects and closes the stream. -
of
static HttpRequest of(RequestHeaders headers, org.reactivestreams.Publisher<? extends HttpObject> publisher)Creates a new instance from an existingRequestHeadersandPublisher.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. -
builder
Returns a newHttpRequestBuilder. -
headers
RequestHeaders headers()Returns the initial HTTP/2 headers of this request. -
uri
Returns the URI of this request. This method is a shortcut forheaders().uri(). -
scheme
Returns the scheme of this request. This method is a shortcut forheaders().scheme(). -
method
Returns the method of this request. This method is a shortcut forheaders().method(). -
path
Returns the path of this request. This method is a shortcut forheaders().path(). -
authority
Returns the authority of this request. This method is a shortcut forheaders().authority(). -
contentType
Returns the value of the'content-type'header.- Returns:
- the valid header value if present, or
nullotherwise.
-
acceptLanguages
Returns a list ofLocale.LanguageRanges that are specified inHttpHeaderNames.ACCEPT_LANGUAGEin the order of client-side preferences. If the client does not send the header, this will contain only a wild cardLocale.LanguageRange. -
selectLocale
Matches theLocales supported by the server to theHttpHeaderNames.ACCEPT_LANGUAGEand returning the best match according to client preference. It does this viaBasic Filtering eachLocale.LanguageRangeand picking the first match. This is the "classic" algorithm described in RFC2616 Accept-Language (obsoleted) and also referenced in RFC7231 Accept-Language. -
selectLocale
Matches theLocales supported by the server to theHttpHeaderNames.ACCEPT_LANGUAGEand returning the best match according to client preference. It does this viaBasic Filtering eachLocale.LanguageRangeand picking the first match. This is the "classic" algorithm described in RFC2616 Accept-Language (obsoleted) and also referenced in RFC7231 Accept-Language. -
withHeaders
Returns a newHttpRequestderived from thisHttpRequestby replacing itsRequestHeaderswith the specifiednewHeaders. Note that the content stream and trailers of thisHttpRequestis not duplicated, which means you can subscribe to only one of the twoHttpRequests.If you are using this method for intercepting an
HttpRequestin 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
Returns a newHttpRequestderived from thisHttpRequestby replacing itsRequestHeaderswith what's built from the specifiednewHeadersBuilder. Note that the content stream and trailers of thisHttpRequestis not duplicated, which means you can subscribe to only one of the twoHttpRequests.If you are using this method for intercepting an
HttpRequestin 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
Aggregates this request. The returnedCompletableFuturewill be notified when the content and the trailers of the request is received fully. -
aggregate
Aggregates this request. The returnedCompletableFuturewill be notified when the content and the trailers of the request is received fully. -
aggregateWithPooledObjects
@UnstableApi default CompletableFuture<AggregatedHttpRequest> aggregateWithPooledObjects(ByteBufAllocator alloc)(Advanced users only) Aggregates this request. The returnedCompletableFuturewill 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().- See Also:
PooledObjects
-
aggregateWithPooledObjects
default CompletableFuture<AggregatedHttpRequest> aggregateWithPooledObjects(EventExecutor executor, ByteBufAllocator alloc)Aggregates this request. The returnedCompletableFuturewill 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: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:
maxRequestLength- 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 duplicatemaxRequestLength- the maximum content length that the duplicator can hold in its buffer.ContentTooLargeExceptionis raised if the length of the bufferedHttpDatais greater than this value.
-
decode
default <T> StreamMessage<T> decode(HttpDecoder<T> decoder, ByteBufAllocator alloc, Function<? super HttpData,? extends ByteBuf> byteBufConverter)Description copied from interface:HttpMessageCreates a decodedStreamMessagewhich is decoded from a stream ofHttpObjects using the specifiedHttpDecoderandByteBufAllocatorandbyteBufConverter.- Specified by:
decodein interfaceHttpMessage
-
mapHeaders
default HttpRequest mapHeaders(Function<? super RequestHeaders,? extends RequestHeaders> function) -
mapData
-
mapTrailers
-