MediaWiki
1.34.0
|
This is a container for storing headers. More...
Public Member Functions | |
addHeader ( $name, $value) | |
Set a header or append to an existing header. More... | |
getHeader ( $name) | |
Get the header with a particular name, or an empty array if there is no such header. More... | |
getHeaderLine ( $name) | |
Get the specified header concatenated into a comma-separated string. More... | |
getHeaderLines () | |
Get all header lines. More... | |
getHeaders () | |
Get header arrays indexed by original name. More... | |
getRawHeaderLines () | |
Get an array of strings of the form "Name: Value", suitable for passing directly to header() to set response headers. More... | |
hasHeader ( $name) | |
Return true if the header exists, false otherwise. More... | |
removeHeader ( $name) | |
Remove a header. More... | |
resetHeaders ( $headers=[]) | |
Erase any existing headers and replace them with the specified header arrays or values. More... | |
setHeader ( $name, $value) | |
Set or replace a header. More... | |
Private Member Functions | |
convertToListAndString ( $value) | |
Take an input header value, which may either be a string or an array, and convert it to an array of header values and a header line. More... | |
Private Attributes | |
$headerLines = [] | |
$headerLists = [] | |
$headerNames = [] | |
This is a container for storing headers.
The header names are case-insensitive, but the case is preserved for methods that return headers in bulk. The header values are a comma-separated list, or equivalently, an array of strings.
Unlike PSR-7, the container is mutable.
Definition at line 12 of file HeaderContainer.php.
MediaWiki\Rest\HeaderContainer::addHeader | ( | $name, | |
$value | |||
) |
Set a header or append to an existing header.
string | $name | |
string | string[] | $value |
Definition at line 90 of file HeaderContainer.php.
References MediaWiki\Rest\HeaderContainer\convertToListAndString().
|
private |
Take an input header value, which may either be a string or an array, and convert it to an array of header values and a header line.
The return value is an array where element 0 has the array of header values, and element 1 has the header line.
Theoretically, if the input is a string, this could parse the string and split it on commas. Doing this is complicated, because some headers can contain double-quoted strings containing commas. The User-Agent header allows commas in comments delimited by parentheses. So it is not just explode(",", $value), we would need to parse a grammar defined by RFC 7231 appendix D which depends on header name.
It's unclear how much it would help handlers to have fully spec-aware HTTP header handling just to split on commas. They would probably be better served by an HTTP header parsing library which provides the full parse tree.
string | string[] | $value | The input header value |
Definition at line 57 of file HeaderContainer.php.
Referenced by MediaWiki\Rest\HeaderContainer\addHeader(), MediaWiki\Rest\HeaderContainer\resetHeaders(), and MediaWiki\Rest\HeaderContainer\setHeader().
MediaWiki\Rest\HeaderContainer::getHeader | ( | $name | ) |
Get the header with a particular name, or an empty array if there is no such header.
string | $name |
Definition at line 137 of file HeaderContainer.php.
MediaWiki\Rest\HeaderContainer::getHeaderLine | ( | $name | ) |
Get the specified header concatenated into a comma-separated string.
If the header does not exist, an empty string is returned.
string | $name |
Definition at line 161 of file HeaderContainer.php.
MediaWiki\Rest\HeaderContainer::getHeaderLines | ( | ) |
Get all header lines.
Definition at line 174 of file HeaderContainer.php.
References MediaWiki\Rest\HeaderContainer\$headerLines.
MediaWiki\Rest\HeaderContainer::getHeaders | ( | ) |
Get header arrays indexed by original name.
Definition at line 126 of file HeaderContainer.php.
References MediaWiki\Rest\HeaderContainer\$headerLists.
MediaWiki\Rest\HeaderContainer::getRawHeaderLines | ( | ) |
Get an array of strings of the form "Name: Value", suitable for passing directly to header() to set response headers.
The PHP manual describes these strings as "raw HTTP headers", so we adopt that terminology.
Definition at line 185 of file HeaderContainer.php.
References $lines.
MediaWiki\Rest\HeaderContainer::hasHeader | ( | $name | ) |
Return true if the header exists, false otherwise.
string | $name |
Definition at line 150 of file HeaderContainer.php.
MediaWiki\Rest\HeaderContainer::removeHeader | ( | $name | ) |
MediaWiki\Rest\HeaderContainer::resetHeaders | ( | $headers = [] | ) |
Erase any existing headers and replace them with the specified header arrays or values.
array | $headers |
Definition at line 23 of file HeaderContainer.php.
References MediaWiki\Rest\HeaderContainer\convertToListAndString().
Referenced by MediaWiki\Rest\RequestBase\setHeaders().
MediaWiki\Rest\HeaderContainer::setHeader | ( | $name, | |
$value | |||
) |
Set or replace a header.
string | $name | |
string | string[] | $value |
Definition at line 71 of file HeaderContainer.php.
References MediaWiki\Rest\HeaderContainer\convertToListAndString().
|
private |
Definition at line 14 of file HeaderContainer.php.
Referenced by MediaWiki\Rest\HeaderContainer\getHeaderLines().
|
private |
Definition at line 13 of file HeaderContainer.php.
Referenced by MediaWiki\Rest\HeaderContainer\getHeaders().
|
private |
Definition at line 15 of file HeaderContainer.php.