class HeaderHelper (View source)

The HeaderHelper class.

Methods

static string
getValue(array $headers, string $name, mixed $default = null)

Get header value.

static boolean
isValidName(mixed $name)

Check whether or not a header name is valid.

static string
filter(string $value)

Method to remove invalid CRLF injection from header value.

static boolean
isValidValue($value)

Method to validate a header value.

static boolean
isValidProtocolVersion(string $version)

Method to validate protocol version format.

static array
allToArray(mixed $value)

Convert values to array.

static boolean
arrayOnlyContainsString(array $array)

Validate is an array only contains string.

static array|string
toHeaderLine(array $headers, bool $toString = false)

Convert every header values to one line and merge multiple values with comma.

static string
normalizeHeaderName(string $header)

Filter a header name to lowercase.

static ResponseInterface
prepareAttachmentHeaders(ResponseInterface $response, string $filename = null)

Prepare attachment headers to response object.

Details

at line line 33
static string getValue(array $headers, string $name, mixed $default = null)

Get header value.

The key will be lower case to search header value and implode array to string by comma.

Parameters

array $headers The headers wqe want to search.
string $name The name to search.
mixed $default The default value if not found.

Return Value

string Found header value.

at line line 59
static boolean isValidName(mixed $name)

Check whether or not a header name is valid.

This method based on phly/http

Parameters

mixed $name The header to validate.

Return Value

boolean Valid or not.

See also

http://tools.ietf.org/html/rfc7230#section-3.2

at line line 78
static string filter(string $value)

Method to remove invalid CRLF injection from header value.

Follows RFC-7230, only allows visible ASCII characters, spaces and tabs in header value. every new line must only contains a single CRLF and a space or tab after it.

Parameters

string $value The value to filter.

Return Value

string Filtered value.

See also

http://en.wikipedia.org/wiki/HTTP_response_splitting
https://tools.ietf.org/html/rfc7230

at line line 131
static boolean isValidValue($value)

Method to validate a header value.

Follows RFC-7230, only allows visible ASCII characters, spaces and tabs in header value. every new line must only contains a single CRLF and a space or tab after it.

Parameters

$value

Return Value

boolean Valid or not.

See also

http://en.wikipedia.org/wiki/HTTP_response_splitting
https://tools.ietf.org/html/rfc7230

at line line 175
static boolean isValidProtocolVersion(string $version)

Method to validate protocol version format.

Only allow 1.0, 1.1 and 2.

Parameters

string $version Version string to validate.

Return Value

boolean Valid or not.

at line line 192
static array allToArray(mixed $value)

Convert values to array.

Parameters

mixed $value Value to convert to array.

Return Value

array Converted array.

at line line 224
static boolean arrayOnlyContainsString(array $array)

Validate is an array only contains string.

Parameters

array $array An array to validate.

Return Value

boolean valid or not.

at line line 252
static array|string toHeaderLine(array $headers, bool $toString = false)

Convert every header values to one line and merge multiple values with comma.

Parameters

array $headers Headers to convert,
bool $toString If true, will implode all header lines with line break.

Return Value

array|string Converted headers.

at line line 280
static string normalizeHeaderName(string $header)

Filter a header name to lowercase.

Parameters

string $header Header name to normalize.

Return Value

string Normalized name.

at line line 296
static ResponseInterface prepareAttachmentHeaders(ResponseInterface $response, string $filename = null)

Prepare attachment headers to response object.

Parameters

ResponseInterface $response The response object.
string $filename Download file name.

Return Value

ResponseInterface