public class HttpHeaders extends Object implements Iterable<HttpHeader>
Constructor and Description |
---|
HttpHeaders()
Create an empty HttpHeaders instance.
|
HttpHeaders(int initialCapacity)
Create a HttpHeaders instance with an initial
size empty headers |
HttpHeaders(Iterable<HttpHeader> headers)
Create a HttpHeaders instance with the provided initial headers.
|
HttpHeaders(Map<String,String> headers)
Create a HttpHeaders instance with the provided initial headers.
|
Modifier and Type | Method and Description |
---|---|
HttpHeader |
get(String name)
Gets the
header for the provided header name. |
int |
getSize()
Gets the number of headers in the collection.
|
String |
getValue(String name)
Get the value for the provided header name.
|
String[] |
getValues(String name)
Get the values for the provided header name.
|
Iterator<HttpHeader> |
iterator() |
HttpHeaders |
put(String name,
String value)
Deprecated.
Use
HttpHeaders.set(String, String) instead. |
HttpHeader |
remove(String name)
Removes the
header with the provided header name. |
HttpHeaders |
set(String name,
List<String> values)
Sets a
header with the given name and the list of values provided, such that the given
values will be comma-separated when necessary. |
HttpHeaders |
set(String name,
String value)
Sets a
header with the given name and value. |
HttpHeaders |
setAll(Map<String,List<String>> headers)
Sets all provided header key/values pairs into this HttpHeaders instance.
|
Stream<HttpHeader> |
stream()
Get a
Stream representation of the HttpHeader values in this instance. |
Map<String,String> |
toMap()
Returns a copy of the http headers as an unmodifiable
Map representation of the state of the
headers at the time of the toMap call. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public HttpHeaders()
public HttpHeaders(Map<String,String> headers)
headers
- the map of initial headerspublic HttpHeaders(Iterable<HttpHeader> headers)
headers
- the collection of initial headerspublic HttpHeaders(int initialCapacity)
size
empty headersinitialCapacity
- the initial capacity of headers map.public int getSize()
@Deprecated public HttpHeaders put(String name, String value)
HttpHeaders.set(String, String)
instead.header
with the given name and value.
If header with same name already exists then the value will be overwritten.
name
- the namevalue
- the valuepublic HttpHeaders set(String name, String value)
header
with the given name and value. If a header with same name already exists then
the value will be overwritten. If the given value is null, the header with the given name will be removed.name
- the name to set in the header. If it is null, this method will return with no changes to the headers.value
- the valuepublic HttpHeaders set(String name, List<String> values)
header
with the given name and the list of values provided, such that the given
values will be comma-separated when necessary. If a header with same name already exists then the
values will be overwritten. If the given values list is null, the header with the given name will be removed.name
- the namevalues
- the values that will be comma-separated as appropriatepublic HttpHeaders setAll(Map<String,List<String>> headers)
headers.forEach(this::set)
, and therefore the behavior is as specified in HttpHeaders.set(String, List)
.
In other words, this will create a header for each key in the provided map, replacing or removing an existing
one, depending on the value. If the given values list is null, the header with the given name will be removed.
If the given name is already a header, it will be removed and replaced with the headers provided.headers
- a map containing keys representing header names, and keys representing the associated values.public HttpHeader get(String name)
header
for the provided header name. Null
is returned if the header isn't
found.name
- the name of the header to find.public HttpHeader remove(String name)
header
with the provided header name. Null
is returned if the header
isn't found.name
- the name of the header to remove.public String getValue(String name)
Null
is returned if the header name isn't found.name
- the name of the header whose value is being retrieved.public String[] getValues(String name)
Null
is returned if the header name isn't found.
This returns getValue
split by comma
.
name
- the name of the header whose value is being retrieved.public Map<String,String> toMap()
Map
representation of the state of the
headers at the time of the toMap call. This map will not change as the underlying http headers change, and nor
will modifying the key or values contained in the map have any effect on the state of the http headers.
Note that there may be performance implications of using Map APIs on the returned Map. It is highly
recommended that users prefer to use alternate APIs present on the HttpHeaders class, over using APIs present
on the returned Map class. For example, use the HttpHeaders.get(String)
API, rather than
httpHeaders.toMap().get(name)
.
public Iterator<HttpHeader> iterator()
iterator
in interface Iterable<HttpHeader>
public Stream<HttpHeader> stream()
Stream
representation of the HttpHeader values in this instance.Stream
of all header values in this instance.Copyright © 2021 Microsoft Corporation. All rights reserved.