‪TYPO3CMS  10.4
TYPO3\CMS\Core\Http\Message Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\Message:
TYPO3\CMS\Core\Http\Request TYPO3\CMS\Core\Http\Response TYPO3\CMS\Core\Http\ServerRequest TYPO3\CMS\Core\Http\HtmlResponse TYPO3\CMS\Core\Http\JsonResponse TYPO3\CMS\Core\Http\NullResponse TYPO3\CMS\Core\Http\RedirectResponse

Public Member Functions

string getProtocolVersion ()
 
array getHeaders ()
 
bool hasHeader ($name)
 
string[] getHeader ($name)
 
string getHeaderLine ($name)
 
Psr Http Message StreamInterface getBody ()
 
string filter ($value)
 
 validateHeaderName ($name)
 
bool isValidHeaderValue ($value)
 

Static Public Member Functions

static withProtocolVersion ($version)
 
static withHeader ($name, $value)
 
static withAddedHeader ($name, $value)
 
static withoutHeader ($name)
 
static withBody (StreamInterface $body)
 

Protected Member Functions

 assertHeaders (array $headers)
 
array filterHeaders (array $originalHeaders)
 
bool arrayContainsOnlyStrings (array $data)
 
 validateHeaderValues (array $values)
 

Protected Attributes

string $protocolVersion = '1.1'
 
array $headers = array( )
 
array $lowercasedHeaderNames = array( )
 
StreamInterface $body
 

Detailed Description

Default implementation for the MessageInterface of the PSR-7 standard It is the base for any request or response for PSR-7.

Highly inspired by https://github.com/phly/http/

Note that this is not public API yet.

Definition at line 29 of file Message.php.

Member Function Documentation

◆ arrayContainsOnlyStrings()

bool TYPO3\CMS\Core\Http\Message::arrayContainsOnlyStrings ( array  $data)
protected

Helper function to test if an array contains only strings

Parameters
array$data
Returns
‪bool

Definition at line 360 of file Message.php.

Referenced by TYPO3\CMS\Core\Http\Message\withAddedHeader(), and TYPO3\CMS\Core\Http\Message\withHeader().

◆ assertHeaders()

TYPO3\CMS\Core\Http\Message::assertHeaders ( array  $headers)
protected

◆ filter()

string TYPO3\CMS\Core\Http\Message::filter (   $value)

Filter a header value

Ensures CRLF header injection vectors are filtered.

Per RFC 7230, only VISIBLE ASCII characters, spaces, and horizontal tabs are allowed in values; header continuations MUST consist of a single CRLF sequence followed by a space or horizontal tab.

This method filters any values not allowed from the string, and is lossy.

See also
http://en.wikipedia.org/wiki/HTTP_response_splitting
Parameters
string$value
Returns
‪string

Definition at line 399 of file Message.php.

◆ filterHeaders()

array TYPO3\CMS\Core\Http\Message::filterHeaders ( array  $originalHeaders)
protected

Filter a set of headers to ensure they are in the correct internal format.

Used by message constructors to allow setting all initial headers at once.

Parameters
array$originalHeaders‪Headers to filter.
Returns
‪array Filtered headers and names.

Definition at line 338 of file Message.php.

References TYPO3\CMS\Core\Http\Message\$headers.

Referenced by TYPO3\CMS\Core\Http\Request\__construct(), and TYPO3\CMS\Core\Http\Response\__construct().

◆ getBody()

◆ getHeader()

string [] TYPO3\CMS\Core\Http\Message::getHeader (   $name)

Retrieves a message header value by the given case-insensitive name.

This method returns an array of all the header values of the given case-insensitive header name.

If the header does not appear in the message, this method MUST return an empty array.

Parameters
string$name‪Case-insensitive header field name.
Returns
‪string[] An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array.

Reimplemented in TYPO3\CMS\Core\Http\Request.

Definition at line 142 of file Message.php.

References TYPO3\CMS\Core\Http\Message\hasHeader().

Referenced by TYPO3\CMS\Core\Http\Message\getHeaderLine(), and TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeaderReturnsHeaderValueAsArray().

◆ getHeaderLine()

string TYPO3\CMS\Core\Http\Message::getHeaderLine (   $name)

Retrieves a comma-separated string of the values for a single header.

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method MUST return an empty string.

Parameters
string$name‪Case-insensitive header field name.
Returns
‪string A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method MUST return an empty string.

Definition at line 174 of file Message.php.

References TYPO3\CMS\Core\Http\Message\getHeader().

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeaderLineReturnsHeaderValueAsCommaConcatenatedString(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderLineWithHostReturnsEmptyStringIfNoUriPresent(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderLineWithHostReturnsEmptyStringIfUriDoesNotContainHost(), and TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderLineWithHostReturnsUriHostWhenPresent().

◆ getHeaders()

array TYPO3\CMS\Core\Http\Message::getHeaders ( )

Retrieves all message header values.

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Returns
‪array Returns an associative array of the message's headers. Each key MUST be a header name, and each value MUST be an array of strings for that header.

Reimplemented in TYPO3\CMS\Core\Http\Request.

Definition at line 110 of file Message.php.

References TYPO3\CMS\Core\Http\Message\$headers.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ResponseTest\constructorIgnoresInvalidHeaders(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeadersKeepsHeaderCaseSensitivity(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeadersReturnsCaseWithWhichHeaderFirstRegistered(), and TYPO3\CMS\Core\Tests\Unit\Http\ResponseTest\testConstructorCanAcceptAllMessageParts().

◆ getProtocolVersion()

string TYPO3\CMS\Core\Http\Message::getProtocolVersion ( )

Retrieves the HTTP protocol version as a string.

The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Returns
‪string HTTP protocol version.

Definition at line 60 of file Message.php.

References TYPO3\CMS\Core\Http\Message\$protocolVersion.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\protocolMutatorReturnsCloneWithChanges().

◆ hasHeader()

bool TYPO3\CMS\Core\Http\Message::hasHeader (   $name)

◆ isValidHeaderValue()

bool TYPO3\CMS\Core\Http\Message::isValidHeaderValue (   $value)

Checks if an HTTP header value is valid.

Per RFC 7230, only VISIBLE ASCII characters, spaces, and horizontal tabs are allowed in values; header continuations MUST consist of a single CRLF sequence followed by a space or horizontal tab.

See also
http://en.wikipedia.org/wiki/HTTP_response_splitting
Parameters
string$value
Returns
‪bool

Definition at line 458 of file Message.php.

Referenced by TYPO3\CMS\Core\Http\Message\assertHeaders(), and TYPO3\CMS\Core\Http\Message\validateHeaderValues().

◆ validateHeaderName()

TYPO3\CMS\Core\Http\Message::validateHeaderName (   $name)

Check whether or not a header name is valid and throw an exception.

See also
https://tools.ietf.org/html/rfc7230#section-3.2
Parameters
string$name
Exceptions

Definition at line 440 of file Message.php.

Referenced by TYPO3\CMS\Core\Http\Message\assertHeaders(), TYPO3\CMS\Core\Http\Message\withAddedHeader(), and TYPO3\CMS\Core\Http\Message\withHeader().

◆ validateHeaderValues()

TYPO3\CMS\Core\Http\Message::validateHeaderValues ( array  $values)
protected

Assert that the provided header values are valid.

See also
https://tools.ietf.org/html/rfc7230#section-3.2
Parameters
string[]$values
Exceptions

Definition at line 374 of file Message.php.

References TYPO3\CMS\Core\Http\Message\isValidHeaderValue().

Referenced by TYPO3\CMS\Core\Http\Message\withAddedHeader(), and TYPO3\CMS\Core\Http\Message\withHeader().

◆ withAddedHeader()

static TYPO3\CMS\Core\Http\Message::withAddedHeader (   $name,
  $value 
)
static

Return an instance with the specified header appended with the given value.

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new header and/or value.

Parameters
string$name‪Case-insensitive header field name to add.
string | string[]$value‪Header value(s).
Returns
‪static
Exceptions

Definition at line 234 of file Message.php.

References TYPO3\CMS\Core\Http\Message\arrayContainsOnlyStrings(), TYPO3\CMS\Core\Http\Message\hasHeader(), TYPO3\CMS\Core\Http\Message\validateHeaderName(), TYPO3\CMS\Core\Http\Message\validateHeaderValues(), and TYPO3\CMS\Core\Http\Message\withHeader().

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\addHeaderAppendsToExistingHeader().

◆ withBody()

static TYPO3\CMS\Core\Http\Message::withBody ( StreamInterface  $body)
static

Return an instance with the specified message body.

The body MUST be a StreamInterface object.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the new body stream.

Parameters
\Psr\Http\Message\StreamInterface$body‪Body.
Returns
‪static
Exceptions

Definition at line 304 of file Message.php.

References TYPO3\CMS\Core\Http\Message\$body.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\bodyMutatorReturnsCloneWithChanges().

◆ withHeader()

static TYPO3\CMS\Core\Http\Message::withHeader (   $name,
  $value 
)
static

Return an instance with the provided value replacing the specified header.

While header names are case-insensitive, the casing of the header will be preserved by this function, and returned from getHeaders().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new and/or updated header and value.

Parameters
string$name‪Case-insensitive header field name.
string | string[]$value‪Header value(s).
Returns
‪static
Exceptions

Definition at line 198 of file Message.php.

References TYPO3\CMS\Core\Http\Message\arrayContainsOnlyStrings(), TYPO3\CMS\Core\Http\Message\validateHeaderName(), and TYPO3\CMS\Core\Http\Message\validateHeaderValues().

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\addHeaderAppendsToExistingHeader(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\canRemoveHeaders(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeaderLineReturnsHeaderValueAsCommaConcatenatedString(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeaderReturnsHeaderValueAsArray(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeadersKeepsHeaderCaseSensitivity(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\getHeadersReturnsCaseWithWhichHeaderFirstRegistered(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\hasHeaderReturnsTrueIfHeaderIsPresent(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\headerRemovalIsCaseInsensitive(), and TYPO3\CMS\Core\Http\Message\withAddedHeader().

◆ withoutHeader()

static TYPO3\CMS\Core\Http\Message::withoutHeader (   $name)
static

Return an instance without the specified header.

Header resolution MUST be done without case-sensitivity.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the named header.

Parameters
string$name‪Case-insensitive header field name to remove.
Returns
‪static

Definition at line 265 of file Message.php.

References TYPO3\CMS\Core\Http\Message\hasHeader().

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\canRemoveHeaders(), TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\headerRemovalIsCaseInsensitive(), and TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\withoutHeaderDoesNothingIfHeaderDoesNotExist().

◆ withProtocolVersion()

static TYPO3\CMS\Core\Http\Message::withProtocolVersion (   $version)
static

Return an instance with the specified HTTP protocol version.

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new protocol version.

Parameters
string$version‪HTTP protocol version
Returns
‪static

Definition at line 78 of file Message.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\MessageTest\protocolMutatorReturnsCloneWithChanges().

Member Data Documentation

◆ $body

◆ $headers

◆ $lowercasedHeaderNames

array TYPO3\CMS\Core\Http\Message::$lowercasedHeaderNames = array( )
protected

Lowercased version of all headers, in order to check if a header is set or not this way a lot of checks are easier to be set

Definition at line 46 of file Message.php.

Referenced by TYPO3\CMS\Core\Http\Request\__construct(), and TYPO3\CMS\Core\Http\Response\__construct().

◆ $protocolVersion

string TYPO3\CMS\Core\Http\Message::$protocolVersion = '1.1'
protected

The HTTP Protocol version, defaults to 1.1

Definition at line 34 of file Message.php.

Referenced by TYPO3\CMS\Core\Http\Message\getProtocolVersion().