On this page
HttpHeaders
class
HttpHeaders
class represents the header configuration options for an HTTP request. Instances should be assumed immutable with lazy parsing.
class HttpHeaders {
constructor(headers?: string | { [name: string]: string | string[]; })
has(name: string): boolean
get(name: string): string | null
keys(): string[]
getAll(name: string): string[] | null
append(name: string, value: string | string[]): HttpHeaders
set(name: string, value: string | string[]): HttpHeaders
delete(name: string, value?: string | string[]): HttpHeaders
}
Constructor
Constructs a new HTTP header object with the given values. |
|||
|
headers |
string | { [name: string]: string | string[]; } |
Optional. Default is |
Methods
has()
|
|||
---|---|---|---|
Checks for existence of a header by a given name. |
|||
|
name |
string |
The header name to check for existence. |
Returns
boolean
: Whether the header exits.
get()
|
|||
---|---|---|---|
Returns the first header value that matches a given name. |
|||
|
name |
string |
The header name to retrieve. |
Returns
string | null
: A string if the header exists, null otherwise
keys()
|
---|
Returns the names of the headers. |
|
getAll()
|
|||
---|---|---|---|
Returns a list of header values for a given header name. |
|||
|
name |
string |
The header name from which to retrieve the values. |
Returns
string[] | null
: A string of values if the header exists, null otherwise.
append()
|
||||||
---|---|---|---|---|---|---|
Appends a new header value to the existing set of header values. |
||||||
|
name |
string |
The header name for which to append the values. |
value |
string | string[] |
Returns
HttpHeaders
: A clone of the HTTP header object with the value appended.
set()
|
||||||
---|---|---|---|---|---|---|
Sets a header value for a given name. If the header name already exists, its value is replaced with the given value. |
||||||
|
name |
string |
The header name. |
value |
string | string[] |
Provides the value to set or overide for a given name. |
Returns
HttpHeaders
: A clone of the HTTP header object with the newly set header value.
delete()
|
||||||
---|---|---|---|---|---|---|
Deletes all header values for a given name. |
||||||
|
name |
string |
The header name. |
value |
string | string[] |
The header values to delete for a given name. Optional. Default is |
Returns
HttpHeaders
: A clone of the HTTP header object.
© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v7.angular.io/api/common/http/HttpHeaders