Package io.servicetalk.http.api
Class HeaderUtils
- java.lang.Object
-
- io.servicetalk.http.api.HeaderUtils
-
public final class HeaderUtils extends java.lang.Object
Utilities to use forHttpHeaders
implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HeaderUtils.CookiesByNameIterator
AnIterator
ofHttpCookiePair
designed to iterate across multiple values ofHttpHeaderNames.COOKIE
for a specificcookie-name
.static class
HeaderUtils.CookiesIterator
-
Field Summary
Fields Modifier and Type Field Description static java.util.function.BiFunction<? super java.lang.CharSequence,? super java.lang.CharSequence,java.lang.CharSequence>
DEFAULT_HEADER_FILTER
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
domainMatches(java.lang.CharSequence requestDomain, java.lang.CharSequence cookieDomain)
static boolean
hasContentType(HttpHeaders headers, java.lang.CharSequence expectedContentType, java.nio.charset.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(java.lang.CharSequence setCookieString, java.lang.CharSequence setCookieName)
static boolean
isTransferEncodingChunked(HttpHeaders headers)
Returnstrue
ifheaders
indicatestransfer-encoding
chunked
.static HttpCookiePair
parseCookiePair(java.lang.CharSequence cookieString, java.lang.CharSequence cookiePairName)
Parse a single cookie-pair from a cookie-string.static HttpSetCookie
parseSetCookie(java.lang.CharSequence setCookieString, java.lang.CharSequence setCookieName, boolean validate)
Parse aHttpSetCookie
from a set-cookie-string.static boolean
pathMatches(java.lang.CharSequence requestPath, java.lang.CharSequence cookiePath)
static java.lang.CharSequence
removeCookiePairs(java.lang.CharSequence cookieString, java.lang.CharSequence cookiePairName)
Remove a single cookie-pair for a cookie-string.
-
-
-
Method Detail
-
isTransferEncodingChunked
public static boolean isTransferEncodingChunked(HttpHeaders headers)
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(java.lang.CharSequence requestDomain, @Nullable java.lang.CharSequence cookieDomain)
- Parameters:
requestDomain
- The domain from the request.cookieDomain
- The domain from the cookie.- Returns:
true
if there is a match.
-
pathMatches
public static boolean pathMatches(java.lang.CharSequence requestPath, @Nullable java.lang.CharSequence cookiePath)
- 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(java.lang.CharSequence setCookieString, java.lang.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(java.lang.CharSequence setCookieString, java.lang.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(java.lang.CharSequence cookieString, java.lang.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 java.lang.CharSequence removeCookiePairs(java.lang.CharSequence cookieString, java.lang.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, java.lang.CharSequence expectedContentType, @Nullable java.nio.charset.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:
- Syntax of the Content-Type Header Field
-
-