Package org.miaixz.bus.http
Class Headers
java.lang.Object
org.miaixz.bus.http.Headers
单个HTTP消息的头字段。值是未解释的字符串; 使用
Request和Response解释头信息 该类维护HTTP消息中的头字段的顺序 这个类从值中删除空白。它从不返回带开头或结尾空白的值- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of bytes required to encode these headers using HTTP/1.1.static longcontentLength(Headers headers) static longcontentLength(Response response) booleanReturns true ifotheris aHeadersobject with the same headers, with the same casing, in the same order.Returns the last value corresponding to the specified field, or null.Returns the last value corresponding to the specified field parsed as an HTTP date, or null if either the field is absent or cannot be parsed as a date.getInstant(String name) Returns the last value corresponding to the specified field parsed as an HTTP date, or null if either the field is absent or cannot be parsed as a date.static booleanReturns true if the response must have a (possibly 0-length) body.inthashCode()static booleanhasVaryAll(Headers responseHeaders) Returns true if a Vary header contains an asterisk.static booleanhasVaryAll(Response response) Returns true if a Vary header contains an asterisk.name(int index) Returns the field atposition.names()Returns an immutable case-insensitive set of header names.static HeadersReturns headers for the alternating header names and values.static HeadersReturns headers for the header names and values in theMap.parseChallenges(Headers responseHeaders, String headerName) Parse RFC 7235 challenges.static intparseSeconds(String value, int defaultValue) Returnsvalueas a positive integer, or 0 if it is negative, ordefaultValueif it cannot be parsed.static voidreceiveHeaders(CookieJar cookieJar, UnoUrl url, Headers headers) intsize()Returns the number of field values.static intReturns the next index ininputat or afterposthat contains a character fromcharacters.static intskipWhitespace(String input, int pos) Returns the next non-whitespace character ininputthat is white space.toString()value(int index) Returns the value atindex.Returns an immutable list of the header values forname.varyFields(Headers responseHeaders) Returns the names of the request headers that need to be checked for equality when caching.static HeadersvaryHeaders(Headers requestHeaders, Headers responseHeaders) Returns the subset of the headers inrequestHeadersthat impact the content of response's body.static HeadersvaryHeaders(Response response) Returns the subset of the headers inresponse's request that impact the content of response's body.static booleanvaryMatches(Response cachedResponse, Headers cachedRequest, Request newRequest) Returns true if none of the Vary headers have changed betweencachedRequestandnewRequest.
-
Method Details
-
of
Returns headers for the alternating header names and values. There must be an even number of arguments, and they must alternate between header names and values. -
of
Returns headers for the header names and values in theMap. -
contentLength
-
contentLength
-
varyMatches
public static boolean varyMatches(Response cachedResponse, Headers cachedRequest, Request newRequest) Returns true if none of the Vary headers have changed betweencachedRequestandnewRequest. -
hasVaryAll
Returns true if a Vary header contains an asterisk. Such responses cannot be cached. -
hasVaryAll
Returns true if a Vary header contains an asterisk. Such responses cannot be cached. -
varyFields
Returns the names of the request headers that need to be checked for equality when caching. -
varyHeaders
Returns the subset of the headers inresponse's request that impact the content of response's body. -
varyHeaders
Returns the subset of the headers inrequestHeadersthat impact the content of response's body. -
parseChallenges
Parse RFC 7235 challenges. This is awkward because we need to look ahead to know how to interpret a token.For example, the first line has a parameter name/value pair and the second line has a single token68:
WWW-Authenticate: Digest foo=bar WWW-Authenticate: Digest foo=Similarly, the first line has one challenge and the second line has two challenges:
WWW-Authenticate: Digest ,foo=bar WWW-Authenticate: Digest ,foo -
receiveHeaders
-
hasBody
Returns true if the response must have a (possibly 0-length) body. See RFC 7231. -
skipUntil
Returns the next index ininputat or afterposthat contains a character fromcharacters. Returns the input length if none of the requested characters can be found. -
skipWhitespace
Returns the next non-whitespace character ininputthat is white space. Result is undefined if input contains newline characters. -
parseSeconds
Returnsvalueas a positive integer, or 0 if it is negative, ordefaultValueif it cannot be parsed. -
newBuilder
-
hashCode
public int hashCode() -
get
Returns the last value corresponding to the specified field, or null. -
getDate
Returns the last value corresponding to the specified field parsed as an HTTP date, or null if either the field is absent or cannot be parsed as a date. -
getInstant
Returns the last value corresponding to the specified field parsed as an HTTP date, or null if either the field is absent or cannot be parsed as a date. -
size
public int size()Returns the number of field values. -
name
Returns the field atposition. -
value
Returns the value atindex. -
names
Returns an immutable case-insensitive set of header names. -
values
Returns an immutable list of the header values forname. -
byteCount
public long byteCount()Returns the number of bytes required to encode these headers using HTTP/1.1. This is also the approximate size of HTTP/2 headers before they are compressed with HPACK. This value is intended to be used as a metric: smaller headers are more efficient to encode and transmit. -
equals
Returns true ifotheris aHeadersobject with the same headers, with the same casing, in the same order. Note that two headers instances may be semantically equal but not equal according to this method. In particular, none of the following sets of headers are equal according to this method:1. Original Content-Type: text/html Content-Length: 50 2. Different order Content-Length: 50 Content-Type: text/html 3. Different case content-type: text/html content-length: 50 4. Different values Content-Type: text/html Content-Length: 050Applications that require semantically equal headers should convert them into a canonical form before comparing them for equality.
-
toString
-
toMultimap
-