Help Angular by taking a 1 minute survey!Go to surveyHome

HttpHeaders

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.

constructor(headers?: string | { [name: string]: string | string[]; })
      
      constructor(headers?: string | { [name: string]: string | string[]; })
    
Parameters
headers string | { [name: string]: string | string[]; }

Optional. Default is undefined.

Methods

Checks for existence of a header by a given name.

has(name: string): boolean
      
      has(name: string): boolean
    
Parameters
name string

The header name to check for existence.

Returns

boolean: Whether the header exits.

Returns the first header value that matches a given name.

get(name: string): string | null
      
      get(name: string): string | null
    
Parameters
name string

The header name to retrieve.

Returns

string | null: A string if the header exists, null otherwise

Returns the names of the headers.

keys(): string[]
      
      keys(): string[]
    
Parameters

There are no parameters.

Returns

string[]: A list of header names.

Returns a list of header values for a given header name.

getAll(name: string): string[] | null
      
      getAll(name: string): string[] | null
    
Parameters
name string

The header name from which to retrieve the values.

Returns

string[] | null: A string of values if the header exists, null otherwise.

Appends a new header value to the existing set of header values.

append(name: string, value: string | string[]): HttpHeaders
      
      append(name: string, value: string | string[]): HttpHeaders
    
Parameters
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.

Sets a header value for a given name. If the header name already exists, its value is replaced with the given value.

set(name: string, value: string | string[]): HttpHeaders
      
      set(name: string, value: string | string[]): HttpHeaders
    
Parameters
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.

Deletes all header values for a given name.

delete(name: string, value?: string | string[]): HttpHeaders
      
      delete(name: string, value?: string | string[]): HttpHeaders
    
Parameters
name string

The header name.

value string | string[]

The header values to delete for a given name.

Optional. Default is undefined.

Returns

HttpHeaders: A clone of the HTTP header object.