Package org.apache.juneau.http.header
Class HttpHeaderList
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<HttpHeader>,Collection<HttpHeader>,List<HttpHeader>,RandomAccess
- Direct Known Subclasses:
HttpHeaderList.Unmodifiable,HttpHeaderList.Void
A mutable, ordered list of
HttpHeader instances.
Mirrors the semantics of HeaderList from juneau-rest-common-classic without the
Apache HttpCore dependency. Header-name comparisons are case-insensitive by default.
Example
HttpHeaderList
See Also:
- Since:
- 10.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn unmodifiable snapshot of aHttpHeaderList.static final classRepresents no header list in annotations. -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor.protectedHttpHeaderList(HttpHeaderList copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionAppends a header constructed from the given name and string value.Appends a header constructed from the given name and lazy value supplier.append(List<HttpHeader> values) Appends the given headers in order.append(HttpHeader value) Appends the given header.append(HttpHeader... values) Appends the given headers in order.caseSensitive(boolean value) Sets whether header-name comparisons are case-sensitive.booleanReturnstrueif a header with the given name is present.copy()Returns a copy of this list.static HttpHeaderListcreate()Creates a new emptyHttpHeaderList.forEach(String name, Consumer<HttpHeader> action) Performs an action on each header whose name matches.getAll()Returns all headers in this list as a typed array.Returns all headers with the given name in insertion order.Returns the first header with the given name, ornullif absent.Returns the last header with the given name, ornullif absent.booleanReturnstrue if this list is an unmodifiable snapshot.static HttpHeaderListof(List<HttpHeader> headers) Creates a newHttpHeaderListinitialized with the given headers.static HttpHeaderListof(HttpHeader... headers) Creates a newHttpHeaderListinitialized with the given headers.static HttpHeaderListRemoves all headers with the given name.Sets a header with the given name and value, replacing any prior entry with the same name.set(HttpHeader value) Sets the given header, replacing any prior entry with the same name.set(HttpHeader... values) Sets the given headers, each replacing any prior entry with the same name.setDefault(String name, String value) Sets a default header with the given name and value (first-in-chain wins per name).setDefault(HttpHeader value) Sets the given header as a default.setDefault(HttpHeader... values) Sets the given headers as defaults, in order.Returns the headers in this list as a typed array.Returns an unmodifiable snapshot of this list.Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll
-
Constructor Details
-
HttpHeaderList
public HttpHeaderList()Constructor. -
HttpHeaderList
Copy constructor.- Parameters:
copyFrom- The list to copy. Must not benull .
-
-
Method Details
-
create
Creates a new emptyHttpHeaderList.- Returns:
- A new instance. Never
null .
-
of
Creates a newHttpHeaderListinitialized with the given headers.- Parameters:
headers- The headers to include.nullentries are ignored.- Returns:
- A new instance. Never
null .
-
of
Creates a newHttpHeaderListinitialized with the given headers.- Parameters:
headers- The headers to include.nullentries are ignored.- Returns:
- A new instance. Never
null .
-
ofPairs
- Parameters:
pairs- Alternating name/value strings. Can benull (treated as empty). Length must be even.- Returns:
- A new instance. Never
null . - Throws:
IllegalArgumentException- If the number of arguments is odd.
-
caseSensitive
Sets whether header-name comparisons are case-sensitive. Defaults tofalse.- Parameters:
value- New value.- Returns:
- This object.
-
append
Appends the given header.- Parameters:
value- The header to add.nullis ignored.- Returns:
- This object.
-
append
Appends the given headers in order.- Parameters:
values- The headers to add.nullentries are ignored.- Returns:
- This object.
-
append
Appends the given headers in order.- Parameters:
values- The headers to add.nullentries are ignored.- Returns:
- This object.
-
append
Appends a header constructed from the given name and string value.- Parameters:
name- The header name. Must not benull .value- The header value. Can benull to omit the header from the request.- Returns:
- This object.
-
append
Appends a header constructed from the given name and lazy value supplier.- Parameters:
name- The header name. Must not benull .value- Supplier of the header value. Must not benull .- Returns:
- This object.
-
setDefault
Sets the given header as a default. If a header with the same name already exists, this is a no-op (first-in-chain wins per name).- Parameters:
value- The header to set.nullis ignored.- Returns:
- This object.
-
setDefault
Sets the given headers as defaults, in order. For each, if a header with the same name already exists, the entry is skipped (first-in-chain wins per name).- Parameters:
values- The headers to set.nullentries are ignored.- Returns:
- This object.
-
setDefault
Sets a default header with the given name and value (first-in-chain wins per name).- Parameters:
name- The header name. Must not benull .value- The header value. Can benull to omit the header from the request.- Returns:
- This object.
-
set
Sets the given header, replacing any prior entry with the same name.- Parameters:
value- The header to set.nullis ignored.- Returns:
- This object.
-
set
Sets the given headers, each replacing any prior entry with the same name.- Parameters:
values- The headers to set.nullentries are ignored.- Returns:
- This object.
-
set
Sets a header with the given name and value, replacing any prior entry with the same name.- Parameters:
name- The header name. Must not benull .value- The header value. Can benull to omit the header from the request.- Returns:
- This object.
-
removeAll
Removes all headers with the given name.- Parameters:
name- The header name. Must not benull .- Returns:
- This object.
-
contains
Returnstrueif a header with the given name is present.- Parameters:
name- The header name.- Returns:
trueif present.
-
getFirst
Returns the first header with the given name, ornullif absent.- Parameters:
name- The header name.- Returns:
- The first matching header, or
null.
-
getLast
Returns the last header with the given name, ornullif absent.- Parameters:
name- The header name.- Returns:
- The last matching header, or
null.
-
getAll
Returns all headers with the given name in insertion order.- Parameters:
name- The header name.- Returns:
- A new list of matching headers. Never
null .
-
getAll
Returns all headers in this list as a typed array.Mirrors
HeaderList.getAll()fromjuneau-rest-common-classic.- Returns:
- A new array. Never
null .
-
forEach
Performs an action on each header whose name matches.- Parameters:
name- The header name.action- The action.- Returns:
- This object.
-
copy
Returns a copy of this list.- Returns:
- A new copy. Never
null .
-
unmodifiable
Returns an unmodifiable snapshot of this list.Idempotency: if this list is already an
HttpHeaderList.Unmodifiablesnapshot, it is returned as-is.- Returns:
- An unmodifiable snapshot of this list, or this list if it is already unmodifiable.
-
isUnmodifiable
Returnstrue if this list is an unmodifiable snapshot.- Returns:
true if this list is anUnmodifiableBeansnapshot.
-
toHeaderArray
Returns the headers in this list as a typed array.- Returns:
- A new array. Never
null .
-