Package io.servicetalk.http.api
Class HeaderUtils
- java.lang.Object
-
- io.servicetalk.http.api.HeaderUtils
-
public final class HeaderUtils extends java.lang.ObjectUtilities to use forHttpHeadersimplementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHeaderUtils.CookiesByNameIteratorAnIteratorofHttpCookiePairdesigned to iterate across multiple values ofHttpHeaderNames.COOKIEfor a specificcookie-name.static classHeaderUtils.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 booleandomainMatches(java.lang.CharSequence requestDomain, java.lang.CharSequence cookieDomain)static booleanhasContentType(HttpHeaders headers, java.lang.CharSequence expectedContentType, java.nio.charset.Charset expectedCharset)Checks if the provider headers contain aContent-Typeheader that matches the specified content type, and optionally the provided charset.static booleanisSetCookieNameMatches(java.lang.CharSequence setCookieString, java.lang.CharSequence setCookieName)static booleanisTransferEncodingChunked(HttpHeaders headers)Returnstrueifheadersindicatestransfer-encodingchunked.static HttpCookiePairparseCookiePair(java.lang.CharSequence cookieString, java.lang.CharSequence cookiePairName)Parse a single cookie-pair from a cookie-string.static HttpSetCookieparseSetCookie(java.lang.CharSequence setCookieString, java.lang.CharSequence setCookieName, boolean validate)Parse aHttpSetCookiefrom a set-cookie-string.static booleanpathMatches(java.lang.CharSequence requestPath, java.lang.CharSequence cookiePath)static java.lang.CharSequenceremoveCookiePairs(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)
Returnstrueifheadersindicatestransfer-encodingchunked.The values of all
HttpHeaderNames.TRANSFER_ENCODINGheaders 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- TheHttpHeadersto check.- Returns:
- true if
headersindicatestransfer-encodingchunked,falseotherwise.
-
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:
trueif 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:
trueif 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:
trueif 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 aHttpSetCookiefrom a set-cookie-string.- Parameters:
setCookieString- The set-cookie-string.setCookieName- The cookie-name.validate-trueto attempt extra validation.- Returns:
- a
HttpSetCookiefrom 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 nullif 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 nullif 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-Typeheader that matches the specified content type, and optionally the provided charset.- Parameters:
headers- theHttpHeadersinstanceexpectedContentType- the content type to look for, provided as atype/subtypeexpectedCharset- an optional charset constraint.- Returns:
trueif aContent-Typeheader that matches the specified content type, and optionally the provided charset has been found,falseotherwise.- See Also:
- Syntax of the Content-Type Header Field
-
-