public class HttpHeaders
extends java.lang.Object
Encapsulates a map of HTTP headers, allowing case-insensitive lookup.
Modifier and Type | Field and Description |
---|---|
static HttpHeaders |
empty |
Constructor and Description |
---|
HttpHeaders() |
Modifier and Type | Method and Description |
---|---|
void |
addAll(HttpHeaders other)
Add all of the headers from another headers object into this headers object.
|
void |
clear()
Clear all the headers.
|
HttpHeaders |
concurrent()
Return a thread-safe headers object that delegates to
this headers object. |
HttpHeaders |
copy()
Return a copy of these headers.
|
boolean |
delete(java.lang.String name)
Delete the value of a header, if present.
|
static HttpHeaders |
emptyIfNull(HttpHeaders headers)
Construct an empty HttpHeaders if the
headers parameter is null . |
StringMap.EntryList |
entries()
Return the header entries (name/value pairs).
|
java.lang.String |
get(java.lang.String name)
Return (nullable) The value of a header, or
null if not found. |
boolean |
has(java.lang.String name)
Return
true if a specified header exists. |
StringList |
keys()
Return the header names.
|
void |
parse(java.lang.String text,
HttpRequest request)
For internal use only.
|
void |
set(java.lang.String name,
java.lang.String value)
Set the value of a header.
|
int |
size()
Return the number of headers.
|
StringMap.EntryList |
sortedEntries()
Return the header entries (name/value pairs) sorted by name (case insensitive).
|
java.lang.String |
toString()
Return headers as a JSON string.
|
HttpHeaders |
with(java.lang.String name,
java.lang.String value)
Set the value of a header.
|
HttpHeaders |
withClientCredentials(StructureBase credentials)
Equivalent to
withData("X-Client-Credentials", value) . |
HttpHeaders |
withCreateParameters(StructureBase parameters)
Equivalent to
withData("X-Create-Parameters", value) . |
HttpHeaders |
withData(java.lang.String header,
java.lang.Object value)
Convert
value to OData 4.0 JSON format, then set a header with the JSON-encoded value as a data URI with media type "application/json" and base64-encoded data. |
HttpHeaders |
withDeleteParameters(StructureBase parameters)
Equivalent to
withData("X-Delete-Parameters", parameters) . |
HttpHeaders |
withUpdateParameters(StructureBase parameters)
Equivalent to
withData("X-Update-Parameters", value) . |
public static final HttpHeaders empty
public void addAll(HttpHeaders other)
Add all of the headers from another headers object into this headers object.
other
- Another headers object.public void clear()
Clear all the headers.
public HttpHeaders concurrent()
Return a thread-safe headers object that delegates to this
headers object.
An HttpHeaders object is not thread-safe for concurrent read/write access. This function will return a thread-safe wrapper.
this
headers object.public HttpHeaders copy()
Return a copy of these headers.
public boolean delete(java.lang.String name)
Delete the value of a header, if present.
name
- Header name.true
if a cookie was deleted.public static HttpHeaders emptyIfNull(HttpHeaders headers)
Construct an empty HttpHeaders if the headers
parameter is null
.
headers
- (nullable) HttpHeaders to be checked.headers
parameter, if non-null
. Otherwise an empty HttpHeaders.public StringMap.EntryList entries()
Return the header entries (name/value pairs).
public java.lang.String get(java.lang.String name)
Return (nullable) The value of a header, or null
if not found.
name
- Header name.null
if not found.public boolean has(java.lang.String name)
Return true
if a specified header exists.
name
- Header name.true
if a specified header exists.public StringList keys()
Return the header names.
public void parse(java.lang.String text, HttpRequest request)
For internal use only.
text
- (internal use only)request
- (internal use only)public void set(java.lang.String name, java.lang.String value)
Set the value of a header.
name
- Header name.value
- Header value.public int size()
Return the number of headers.
public StringMap.EntryList sortedEntries()
Return the header entries (name/value pairs) sorted by name (case insensitive).
public java.lang.String toString()
Return headers as a JSON string.
toString
in class java.lang.Object
public HttpHeaders with(java.lang.String name, java.lang.String value)
Set the value of a header.
name
- Header name.value
- Header value.public HttpHeaders withClientCredentials(StructureBase credentials)
Equivalent to withData("X-Client-Credentials", value)
.
credentials
- Client credentials.public HttpHeaders withCreateParameters(StructureBase parameters)
Equivalent to withData("X-Create-Parameters", value)
.
parameters
- Create parameters.public HttpHeaders withData(java.lang.String header, java.lang.Object value)
Convert value
to OData 4.0 JSON format, then set a header with the JSON-encoded value as a data URI with media type "application/json" and base64-encoded data.
header
- Header name.value
- (nullable) Header value.public HttpHeaders withDeleteParameters(StructureBase parameters)
Equivalent to withData("X-Delete-Parameters", parameters)
.
parameters
- Delete parameters.public HttpHeaders withUpdateParameters(StructureBase parameters)
Equivalent to withData("X-Update-Parameters", value)
.
parameters
- Update parameters.