Package org.apache.hc.core5.http.message
Class HeaderGroup
java.lang.Object
org.apache.hc.core5.http.message.HeaderGroup
- All Implemented Interfaces:
Serializable,MessageHeaders
- Direct Known Subclasses:
BasicHttpRequest,BasicHttpResponse
A class for combining a set of headers. This class allows for multiple headers with the same name
and keeps track of the order in which headers were added.
- Since:
- 4.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given header to the group.voidclear()Removes all headers.booleancontainsHeader(String name) Tests if headers with the given name are contained within this group.intcountHeaders(String name) Checks if a certain header is present in this message and how many times.getCondensedHeader(String name) Gets a header representing all of the header values with the given name.getFirstHeader(String name) Gets the first header with the given name.Gets single first header with the given name.Header[]Gets all of the headers contained within this group.Header[]getHeaders(String name) Gets all of the headers with the given name.getLastHeader(String name) Gets the last header with the given name.private booleanheaderEquals(Header header1, Header header2) Returns an iterator over this group of headers.headerIterator(String name) Returns an iterator over the headers with a given name in this group.booleanremoveHeader(Header header) Removes the first given header.booleanremoveHeaders(String name) Removes all headers with a given name in this group.booleanremoveHeaders(Header header) Removes all headers that match the given header.voidReplaces the first occurrence of the header with the same name.voidsetHeaders(Header... headers) Sets all of the headers contained within this group overriding any existing headers.toString()
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
EMPTY
-
headers
The list of headers for this group, in the order in which they were added
-
-
Constructor Details
-
HeaderGroup
public HeaderGroup()Constructor for HeaderGroup.
-
-
Method Details
-
clear
public void clear()Removes all headers. -
addHeader
Adds the given header to the group. The order in which this header was added is preserved.- Parameters:
header- the header to add
-
removeHeader
Removes the first given header.- Parameters:
header- the header to remove- Returns:
trueif a header was removed as a result of this call.
-
headerEquals
-
removeHeaders
Removes all headers that match the given header.- Parameters:
header- the header to remove- Returns:
trueif any header was removed as a result of this call.- Since:
- 5.0
-
setHeader
Replaces the first occurrence of the header with the same name. If no header with the same name is found the given header is added to the end of the list.- Parameters:
header- the new header that should replace the first header with the same name if present in the list.- Since:
- 5.0
-
setHeaders
Sets all of the headers contained within this group overriding any existing headers. The headers are added in the order in which they appear in the array.- Parameters:
headers- the headers to set
-
getCondensedHeader
Gets a header representing all of the header values with the given name. If more that one header with the given name exists the values will be combined with a ",".Header name comparison is case insensitive.
- Parameters:
name- the name of the header(s) to get- Returns:
- a header with a condensed value or
nullif no headers by the given name are present
-
getHeaders
Gets all of the headers with the given name. The returned array maintains the relative order in which the headers were added.Header name comparison is case insensitive.
- Specified by:
getHeadersin interfaceMessageHeaders- Parameters:
name- the name of the header(s) to get- Returns:
- an array of length ≥ 0
-
getFirstHeader
Gets the first header with the given name.Header name comparison is case insensitive.
- Specified by:
getFirstHeaderin interfaceMessageHeaders- Parameters:
name- the name of the header to get- Returns:
- the first header or
null
-
getHeader
Gets single first header with the given name.Header name comparison is case insensitive.
- Specified by:
getHeaderin interfaceMessageHeaders- Parameters:
name- the name of the header to get- Returns:
- the first header or
null - Throws:
ProtocolException- in case multiple headers with the given name are found.
-
getLastHeader
Gets the last header with the given name.Header name comparison is case insensitive.
- Specified by:
getLastHeaderin interfaceMessageHeaders- Parameters:
name- the name of the header to get- Returns:
- the last header or
null
-
getHeaders
Gets all of the headers contained within this group.- Specified by:
getHeadersin interfaceMessageHeaders- Returns:
- an array of length ≥ 0
-
containsHeader
Tests if headers with the given name are contained within this group.Header name comparison is case insensitive.
- Specified by:
containsHeaderin interfaceMessageHeaders- Parameters:
name- the header name to test for- Returns:
trueif at least one header with the name is contained,falseotherwise
-
countHeaders
Checks if a certain header is present in this message and how many times.Header name comparison is case insensitive.
- Specified by:
countHeadersin interfaceMessageHeaders- Parameters:
name- the header name to check for.- Returns:
- number of occurrences of the header in the message.
-
headerIterator
Returns an iterator over this group of headers.- Specified by:
headerIteratorin interfaceMessageHeaders- Returns:
- iterator over this group of headers.
- Since:
- 5.0
-
headerIterator
Returns an iterator over the headers with a given name in this group.- Specified by:
headerIteratorin interfaceMessageHeaders- Parameters:
name- the name of the headers over which to iterate, ornullfor all headers- Returns:
- iterator over some headers in this group.
- Since:
- 5.0
-
removeHeaders
Removes all headers with a given name in this group.- Parameters:
name- the name of the headers to be removed.- Returns:
trueif any header was removed as a result of this call.- Since:
- 5.0
-
toString
-