Package io.servicetalk.http.api
Class HeaderUtils
java.lang.Object
io.servicetalk.http.api.HeaderUtils
Utilities to use for
HttpHeaders
implementations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
AnIterator
ofHttpCookiePair
designed to iterate across multiple values ofHttpHeaderNames.COOKIE
for a specificcookie-name
.static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BiFunction<? super CharSequence,
? super CharSequence, CharSequence> -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
domainMatches
(CharSequence requestDomain, CharSequence cookieDomain) static boolean
hasContentType
(HttpHeaders headers, CharSequence expectedContentType, Charset expectedCharset) Checks if the provider headers contain aContent-Type
header that matches the specified content type, and optionally the provided charset.static boolean
isSetCookieNameMatches
(CharSequence setCookieString, CharSequence setCookieName) static boolean
isTransferEncodingChunked
(HttpHeaders headers) Returnstrue
ifheaders
indicatestransfer-encoding
chunked
.static HttpCookiePair
parseCookiePair
(CharSequence cookieString, CharSequence cookiePairName) Parse a single cookie-pair from a cookie-string.static HttpSetCookie
parseSetCookie
(CharSequence setCookieString, CharSequence setCookieName, boolean validate) Parse aHttpSetCookie
from a set-cookie-string.static boolean
pathMatches
(CharSequence requestPath, CharSequence cookiePath) static CharSequence
removeCookiePairs
(CharSequence cookieString, CharSequence cookiePairName) Remove a single cookie-pair for a cookie-string.
-
Field Details
-
DEFAULT_HEADER_FILTER
public static final BiFunction<? super CharSequence,? super CharSequence, DEFAULT_HEADER_FILTERCharSequence>
-
-
Method Details
-
isTransferEncodingChunked
Returnstrue
ifheaders
indicatestransfer-encoding
chunked
.The values of all
HttpHeaderNames.TRANSFER_ENCODING
headers are interpreted as comma-separated values, with spaces between values trimmed. If any of these values isHttpHeaderValues.CHUNKED
, this method returntrue
, otherwise it returnsfalse
.- Parameters:
headers
- TheHttpHeaders
to check.- Returns:
- true if
headers
indicatestransfer-encoding
chunked
,false
otherwise.
-
domainMatches
public static boolean domainMatches(CharSequence requestDomain, @Nullable CharSequence cookieDomain) - Parameters:
requestDomain
- The domain from the request.cookieDomain
- The domain from the cookie.- Returns:
true
if there is a match.
-
pathMatches
- Parameters:
requestPath
- The path from the request.cookiePath
- The path from the cookie.- Returns:
true
if there is a match.
-
isSetCookieNameMatches
public static boolean isSetCookieNameMatches(CharSequence setCookieString, CharSequence setCookieName) - Parameters:
setCookieString
- The set-cookie-string.setCookieName
- The cookie-name.- Returns:
true
if a set-cookie-string's cookie-name matchessetCookieName
.
-
parseSetCookie
@Nullable public static HttpSetCookie parseSetCookie(CharSequence setCookieString, CharSequence setCookieName, boolean validate) Parse aHttpSetCookie
from a set-cookie-string.- Parameters:
setCookieString
- The set-cookie-string.setCookieName
- The cookie-name.validate
-true
to attempt extra validation.- Returns:
- a
HttpSetCookie
from a set-cookie-string.
-
parseCookiePair
@Nullable public static HttpCookiePair parseCookiePair(CharSequence cookieString, CharSequence cookiePairName) Parse a single cookie-pair from a cookie-string.- Parameters:
cookieString
- The cookie-string that may contain multiple cookie-pairs.cookiePairName
- The cookie-name identifying the cookie-pairs to parse.- Returns:
- The first cookie-pair from a
cookie-string whose
cookie-name matched
cookiePairName
null
if no matches were found
- The first cookie-pair from a
cookie-string whose
cookie-name matched
-
removeCookiePairs
@Nullable public static CharSequence removeCookiePairs(CharSequence cookieString, CharSequence cookiePairName) Remove a single cookie-pair for a cookie-string.- Parameters:
cookieString
- The cookie-string that may contain multiple cookie-pairs.cookiePairName
- The cookie-name identifying the cookie-pairs to remove.- Returns:
- The cookie-string value with all
cookie-pairs removed whose
cookie-name matches
cookiePairName
- Empty if all the cookie-pairs matched
cookiePairName
null
if none of the cookie-pairs matchedcookiePairName
- The cookie-string value with all
cookie-pairs removed whose
cookie-name matches
-
hasContentType
public static boolean hasContentType(HttpHeaders headers, CharSequence expectedContentType, @Nullable Charset expectedCharset) Checks if the provider headers contain aContent-Type
header that matches the specified content type, and optionally the provided charset.- Parameters:
headers
- theHttpHeaders
instanceexpectedContentType
- the content type to look for, provided as atype/subtype
expectedCharset
- an optional charset constraint.- Returns:
true
if aContent-Type
header that matches the specified content type, and optionally the provided charset has been found,false
otherwise.- See Also:
-