W3cubDocs

/Angular

HttpHeaders

class final

Represents the header configuration options for an HTTP request. Instances are immutable. Modifying methods return a cloned instance with the change. The original object is never changed.

class HttpHeaders {
  constructor(headers?: string | { [name: string]: string | number | (string | number)[]; } | Headers)
  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.

This class is "final" and should not be extended. See the public API notes.

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

Parameters
headers string | { [name: string]: string | number | (string | number)[]; } | Headers

Optional. Default is undefined.

Methods

Checks for existence of a given header.

has(name: string): boolean

Parameters
name string

The header name to check for existence.

Returns

boolean: True if the header exists, false otherwise.

Retrieves the first value of a given header.

get(name: string): string | null

Parameters
name string

The header name.

Returns

string | null: The value string if the header exists, null otherwise

Retrieves the names of the headers.

keys(): string[]

Parameters

There are no parameters.

Returns

string[]: A list of header names.

Retrieves a list of values for a given header.

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

Parameters
name string

The header name from which to retrieve values.

Returns

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

Appends a new value to the existing set of values for a header and returns them in a clone of the original instance.

append(name: string, value: string | string[]): HttpHeaders

Parameters
name string

The header name for which to append the values.

value string | string[]

The value to append.

Returns

HttpHeaders: A clone of the HTTP headers object with the value appended to the given header.

Sets or modifies a value for a given header in a clone of the original instance. If the header already exists, its value is replaced with the given value in the returned object.

set(name: string, value: string | string[]): HttpHeaders

Parameters
name string

The header name.

value string | string[]

The value or values to set or override for the given header.

Returns

HttpHeaders: A clone of the HTTP headers object with the newly set header value.

Deletes values for a given header in a clone of the original instance.

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

Parameters
name string

The header name.

value string | string[]

The value or values to delete for the given header.

Optional. Default is undefined.

Returns

HttpHeaders: A clone of the HTTP headers object with the given value deleted.

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/common/http/HttpHeaders