HttpHeaders
HTTP headers.
Tags
Table of Contents
- __construct() : mixed
- Constructor.
- add() : HttpHeaders
- Add a pair of HTTP header name and value.
- get() : array<string|int, mixed>
- Get the values of an HTTP header.
- getFirst() : string
- Get the first value of an HTTP header.
- getMap() : array<string|int, mixed>
- Get a map that holds pairs of HTTP header name and values.
- parse() : HttpHeaders
- Parse HTTP headers and generate an instance of HttpHeaders that represents the HTTP headers.
Methods
__construct()
Constructor.
public
__construct() : mixed
Return values
mixed —add()
Add a pair of HTTP header name and value.
public
add(string $name, string $value) : HttpHeaders
Parameters
- $name : string
-
HTTP header name. For example,
Location
. - $value : string
-
HTTP header value.
Return values
HttpHeaders —$this
object.
get()
Get the values of an HTTP header.
public
get(string $name) : array<string|int, mixed>
Parameters
- $name : string
-
HTTP header name. For example,
Location
. Case-insensitive.
Return values
array<string|int, mixed> —Values of the HTTP header.
getFirst()
Get the first value of an HTTP header.
public
getFirst(string $name) : string
Parameters
- $name : string
-
HTTP header name. For example,
Location
. Case-insensitive.
Return values
string —The first value of the HTTP header.
getMap()
Get a map that holds pairs of HTTP header name and values.
public
getMap() : array<string|int, mixed>
Return values
array<string|int, mixed> —A map that holds pairs of HTTP header name and values.
parse()
Parse HTTP headers and generate an instance of HttpHeaders that represents the HTTP headers.
public
static parse(string $input) : HttpHeaders
$input = "Fruits: Apple\r\n"
. "fruits: Banana\r\n"
. "FRUITS: Cherry\r\n"
. "Animals: Cat\r\n"
;
$headers = HttpHeaders::parse($input);
Parameters
- $input : string
-
HTTP headers delimited by newlines (CRLF or LF).
Return values
HttpHeaders —An HttpHeaders instance that represents the given HTTP headers.