Package com.linecorp.armeria.common
Interface RequestHeaders
- All Superinterfaces:
HttpHeaders
,HttpObject
,Iterable<Map.Entry<AsciiString,String>>
public interface RequestHeaders extends HttpHeaders
Immutable HTTP/2 headers for an
HttpRequest
.- See Also:
HttpHeaders
,ResponseHeaders
-
Method Summary
Modifier and Type Method Description String
authority()
Returns the value of the":authority"
for HTTP/2 request or"Host"
header for HTTP/1.1.static RequestHeadersBuilder
builder()
Returns a new empty builder.static RequestHeadersBuilder
builder(HttpMethod method, String path)
Returns a new builder with the specifiedHttpMethod
andpath
.boolean
contains(CharSequence name)
Returnstrue
if a header with thename
exists,false
otherwise.boolean
contains(CharSequence name, String value)
Returnstrue
if a header with thename
andvalue
exists.boolean
containsDouble(CharSequence name, double value)
Returnstrue
if a header with thename
andvalue
exists.boolean
containsFloat(CharSequence name, float value)
Returnstrue
if a header with thename
andvalue
exists.boolean
containsInt(CharSequence name, int value)
Returnstrue
if a header with thename
andvalue
exists.boolean
containsLong(CharSequence name, long value)
Returnstrue
if a header with thename
andvalue
exists.boolean
containsObject(CharSequence name, Object value)
Returnstrue
if a header with thename
andvalue
exists.boolean
containsTimeMillis(CharSequence name, long value)
Returnstrue
if a header with thename
andvalue
exists.MediaType
contentType()
Returns the parsed"content-type"
header.void
forEach(BiConsumer<AsciiString,String> action)
Invokes the specifiedaction
for all header entries.void
forEachValue(CharSequence name, Consumer<String> action)
Invokes the specifiedaction
for all values of the headers with the specifiedname
.String
get(CharSequence name)
Returns the value of a header with the specifiedname
.String
get(CharSequence name, String defaultValue)
Returns the value of a header with the specifiedname
.List<String>
getAll(CharSequence name)
Returns all values for the header with the specified name.Double
getDouble(CharSequence name)
Returns thedouble
value of a header with the specifiedname
.double
getDouble(CharSequence name, double defaultValue)
Returns thedouble
value of a header with the specifiedname
.Float
getFloat(CharSequence name)
Returns thefloat
value of a header with the specifiedname
.float
getFloat(CharSequence name, float defaultValue)
Returns thefloat
value of a header with the specifiedname
.Integer
getInt(CharSequence name)
Returns theint
value of a header with the specifiedname
.int
getInt(CharSequence name, int defaultValue)
Returns theint
value of a header with the specifiedname
.Long
getLong(CharSequence name)
Returns thelong
value of a header with the specifiedname
.long
getLong(CharSequence name, long defaultValue)
Returns thelong
value of a header with the specifiedname
.Long
getTimeMillis(CharSequence name)
Returns the value of a header with the specifiedname
in milliseconds.long
getTimeMillis(CharSequence name, long defaultValue)
Returns the value of a header with the specifiedname
in milliseconds.boolean
isEmpty()
Returnstrue
if this headers does not contain any entries.boolean
isEndOfStream()
Tells whether the headers correspond to the last frame in an HTTP/2 stream.Iterator<Map.Entry<AsciiString,String>>
iterator()
Returns anIterator
that yields all header entries.HttpMethod
method()
Returns the value of the":method"
header as anHttpMethod
.Set<AsciiString>
names()
Returns aSet
of all header names.static RequestHeaders
of(HttpHeaders headers)
Returns a newRequestHeaders
copied from the specifiedHttpHeaders
.static RequestHeaders
of(HttpMethod method, String path)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name, Object value)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2, CharSequence name3, Object value3)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2, CharSequence name3, Object value3, CharSequence name4, Object value4)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name, String value)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2, CharSequence name3, String value3)
static RequestHeaders
of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2, CharSequence name3, String value3, CharSequence name4, String value4)
String
path()
Returns the value of the":path"
header.String
scheme()
Returns the value of the":scheme"
header ornull
if there is no such header.int
size()
Returns the number of headers.default Stream<Map.Entry<AsciiString,String>>
stream()
Returns aStream
that yields all header entries.RequestHeadersBuilder
toBuilder()
Returns a new builder created from the entries of this headers.URI
uri()
Returns the request URI generated from the":scheme"
,":authority"
and":path"
headers.Iterator<String>
valueIterator(CharSequence name)
Returns anIterator
that yields all values of the headers with the specifiedname
.default Stream<String>
valueStream(CharSequence name)
Returns aStream
that yields all values of the headers with the specifiedname
.default RequestHeaders
withMutations(Consumer<HttpHeadersBuilder> mutator)
Returns a new headers which is the result from the mutation by the specifiedConsumer
.
-
Method Details
-
builder
Returns a new empty builder. -
builder
Returns a new builder with the specifiedHttpMethod
andpath
. -
of
-
of
-
of
Returns a newRequestHeaders
with the specifiedHttpMethod
,path
and an additional header. The value is converted into aString
as explained in Specifying a non-String header value. -
of
static RequestHeaders of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2) -
of
static RequestHeaders of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2)Returns a newRequestHeaders
with the specifiedHttpMethod
,path
and additional headers. The values are converted intoString
s as explained in Specifying a non-String header value. -
of
static RequestHeaders of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2, CharSequence name3, String value3) -
of
static RequestHeaders of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2, CharSequence name3, Object value3)Returns a newRequestHeaders
with the specifiedHttpMethod
,path
and additional headers. The values are converted intoString
s as explained in Specifying a non-String header value. -
of
static RequestHeaders of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2, CharSequence name3, String value3, CharSequence name4, String value4) -
of
static RequestHeaders of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2, CharSequence name3, Object value3, CharSequence name4, Object value4)Returns a newRequestHeaders
with the specifiedHttpMethod
,path
and additional headers. The values are converted intoString
s as explained in Specifying a non-String header value. -
of
Returns a newRequestHeaders
copied from the specifiedHttpHeaders
.- Throws:
IllegalArgumentException
- if the specifiedHttpHeaders
does not have":method"
or":path"
header.
-
toBuilder
RequestHeadersBuilder toBuilder()Description copied from interface:HttpHeaders
Returns a new builder created from the entries of this headers.- Specified by:
toBuilder
in interfaceHttpHeaders
- See Also:
HttpHeaders.withMutations(Consumer)
-
withMutations
Description copied from interface:HttpHeaders
Returns a new headers which is the result from the mutation by the specifiedConsumer
. This method is a shortcut for:builder = toBuilder(); mutator.accept(builder); return builder.build();
- Specified by:
withMutations
in interfaceHttpHeaders
- See Also:
HttpHeaders.toBuilder()
-
isEndOfStream
boolean isEndOfStream()Tells whether the headers correspond to the last frame in an HTTP/2 stream. -
contentType
Returns the parsed"content-type"
header.- Returns:
- the parsed
MediaType
if present and valid, ornull
otherwise.
-
get
Returns the value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve- Returns:
- the first header value if the header is found, or
null
if there's no such header
-
get
Returns the value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrievedefaultValue
- the default value- Returns:
- the first header value or
defaultValue
if there is no such header
-
getAll
Returns all values for the header with the specified name. The returnedList
can't be modified. -
getInt
Returns theint
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve- Returns:
- the
int
value of the first value in insertion order ornull
if there is no such header or it can't be converted toint
.
-
getInt
Returns theint
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrievedefaultValue
- the default value- Returns:
- the
int
value of the first value in insertion order ordefaultValue
if there is no such header or it can't be converted toint
.
-
getLong
Returns thelong
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve- Returns:
- the
long
value of the first value in insertion order ornull
if there is no such header or it can't be converted tolong
.
-
getLong
Returns thelong
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrievedefaultValue
- the default value- Returns:
- the
long
value of the first value in insertion order ordefaultValue
if there is no such header or it can't be converted tolong
.
-
getFloat
Returns thefloat
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve- Returns:
- the
float
value of the first value in insertion order ornull
if there is no such header or it can't be converted tofloat
.
-
getFloat
Returns thefloat
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrievedefaultValue
- the default value- Returns:
- the
float
value of the first value in insertion order ordefaultValue
if there is no such header or it can't be converted tofloat
.
-
getDouble
Returns thedouble
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve- Returns:
- the
double
value of the first value in insertion order ornull
if there is no such header or it can't be converted todouble
.
-
getDouble
Returns thedouble
value of a header with the specifiedname
. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrievedefaultValue
- the default value- Returns:
- the
double
value of the first value in insertion order ordefaultValue
if there is no such header or it can't be converted todouble
.
-
getTimeMillis
Returns the value of a header with the specifiedname
in milliseconds. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrieve- Returns:
- the milliseconds value of the first value in insertion order or
null
if there is no such header or it can't be converted to milliseconds.
-
getTimeMillis
Returns the value of a header with the specifiedname
in milliseconds. If there are more than one value for the specifiedname
, the first value in insertion order is returned.- Parameters:
name
- the name of the header to retrievedefaultValue
- the default value- Returns:
- the milliseconds value of the first value in insertion order or
defaultValue
if there is no such header or it can't be converted to milliseconds.
-
contains
Returnstrue
if a header with thename
exists,false
otherwise.- Parameters:
name
- the header name
-
contains
Returnstrue
if a header with thename
andvalue
exists.- Parameters:
name
- the header namevalue
- the header value of the header to find
-
containsObject
Returnstrue
if a header with thename
andvalue
exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
true
if the header exists.false
otherwise
-
containsInt
Returnstrue
if a header with thename
andvalue
exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
true
if the header exists.false
otherwise
-
containsLong
Returnstrue
if a header with thename
andvalue
exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
true
if the header exists.false
otherwise
-
containsFloat
Returnstrue
if a header with thename
andvalue
exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
true
if the header exists.false
otherwise
-
containsDouble
Returnstrue
if a header with thename
andvalue
exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
true
if the header exists.false
otherwise
-
containsTimeMillis
Returnstrue
if a header with thename
andvalue
exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
true
if the header exists.false
otherwise
-
size
int size()Returns the number of headers. -
isEmpty
boolean isEmpty()Returnstrue
if this headers does not contain any entries. -
names
Set<AsciiString> names() -
iterator
Iterator<Map.Entry<AsciiString,String>> iterator()Returns anIterator
that yields all header entries. The iteration order is as follows:- All pseudo headers (order not specified).
- All non-pseudo headers (in insertion order).
- Specified by:
iterator
in interfaceIterable<Map.Entry<AsciiString,String>>
-
valueIterator
Returns anIterator
that yields all values of the headers with the specifiedname
. -
forEach
Invokes the specifiedaction
for all header entries. -
forEachValue
Invokes the specifiedaction
for all values of the headers with the specifiedname
. -
stream
Returns aStream
that yields all header entries. -
valueStream
Returns aStream
that yields all values of the headers with the specifiedname
. -
uri
URI uri()Returns the request URI generated from the":scheme"
,":authority"
and":path"
headers.- Throws:
IllegalStateException
- if any of the required headers do not exist or the resulting URI is not valid.
-
method
HttpMethod method()Returns the value of the":method"
header as anHttpMethod
.HttpMethod.UNKNOWN
is returned if the value is not defined inHttpMethod
.- Throws:
IllegalStateException
- if there is no such header.
-
path
String path()Returns the value of the":path"
header.- Throws:
IllegalStateException
- if there is no such header.
-
scheme
Returns the value of the":scheme"
header ornull
if there is no such header. -
authority
Returns the value of the":authority"
for HTTP/2 request or"Host"
header for HTTP/1.1.null
if there is no such headers.
-