填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

HttpHeaders

Http 头的不可变集合,惰性解析。

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 | 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
}
    

构造函数

Constructs a new HTTP header object with the given values.

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

可选. 默认值是 undefined.

方法

检查是否存在指定名称的头。

Checks for existence of a given header.

has(name: string): boolean
      
      has(name: string): boolean
    
参数
name string

要检查是否存在的头名称

The header name to check for existence.

返回值

这个头是否存在。

boolean: True if the header exists, false otherwise.

返回匹配指定名称的第一个头的值。

Retrieves the first value of a given header.

get(name: string): string | null
      
      get(name: string): string | null
    
参数
name string

要取的头名称

The header name.

返回值

如果头存在则返回一个字符串,否则返回 null

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

返回所有的头名称。

Retrieves the names of the headers.

keys(): string[]
      
      keys(): string[]
    
参数

没有参数。

返回值

一个头名称列表。

string[]: A list of header names.

返回头中具有指定名称的值的列表。

Retrieves a list of values for a given header.

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

准备获取值的头名称

The header name from which to retrieve values.

返回值

如果头存在则返回一个字符串数组,否则返回 null。

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

The header name for which to append the values.

value string | string[]

The value to append.

返回值

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

The header name.

value string | string[]

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

返回值

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
      
      delete(name: string, value?: string | string[]): HttpHeaders
    
参数
name string

The header name.

value string | string[]

可选. 默认值是 undefined.

The value or values to delete for the given header.

返回值

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