Headers
class
deprecated
Polyfill for Headers, as specified in the Fetch Spec.
Deprecated: see https://angular.io/guide/http
class Headers { static fromResponseHeaderString(headersString: string): Headers constructor(headers?: Headers | {...}) append(name: string, value: string): void delete(name: string): void forEach(fn: (values: string[], name: string | undefined, headers: Map<string, string[]>) => void): void get(name: string): string | null has(name: string): boolean keys(): string[] set(name: string, value: string | string[]): void values(): string[][] toJSON(): {...} getAll(name: string): string[] | null entries() }
Description
The only known difference between this Headers
implementation and the spec is the lack of an entries
method.
Static methods
fromResponseHeaderString() | ||
---|---|---|
Returns a new Headers instance from the given DOMString of Response Headers | ||
|
headersString | Type: |
Returns
Constructor
|
headers | Type: Optional. Default is |
Methods
append() | ||||
---|---|---|---|---|
Appends a header to existing list of header values for a given header name. | ||||
|
name | Type: |
value | Type: |
Returns
void
delete() | ||
---|---|---|
Deletes all header values for the given name. | ||
|
name | Type: |
Returns
void
forEach() | ||
---|---|---|
|
fn | Type: |
Returns
void
get() | ||
---|---|---|
Returns first header that matches given name. | ||
|
name | Type: |
Returns
string | null
has() | ||
---|---|---|
Checks for existence of header by given name. | ||
|
name | Type: |
Returns
boolean
keys() |
---|
Returns the names of the headers |
|
set() | ||||
---|---|---|---|---|
Sets or overrides header value for given name. | ||||
|
name | Type: |
value | Type: |
Returns
void
values() |
---|
Returns values of all headers. |
|
toJSON() |
---|
Returns string of all headers. |
|
getAll() | ||
---|---|---|
Returns list of header values for a given name. | ||
|
name | Type: |
Returns
string[] | null
entries() |
---|
This method is not implemented. |
|
Usage notes
Example
import {Headers} from '@angular/http'; var firstHeaders = new Headers(); firstHeaders.append('Content-Type', 'image/jpeg'); console.log(firstHeaders.get('Content-Type')) //'image/jpeg' // Create headers from Plain Old JavaScript Object var secondHeaders = new Headers({ 'X-My-Custom-Header': 'Angular' }); console.log(secondHeaders.get('X-My-Custom-Header')); //'Angular' var thirdHeaders = new Headers(secondHeaders); console.log(thirdHeaders.get('X-My-Custom-Header')); //'Angular'
© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v6.angular.io/api/http/Headers