‪TYPO3CMS  ‪main
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 TYPO3\CMS\Extbase\Http\ForwardResponse

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

string $protocolVersion = '1.1'
 
array $headers = []
 
array $lowercasedHeaderNames = []
 
StreamInterface $body = null
 

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 31 of file Message.php.

Member Function Documentation

◆ arrayContainsOnlyStrings()

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

Helper function to test if an array contains only strings

Definition at line 359 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()

TYPO3\CMS\Core\Http\Message::filter ( string  $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
Todo:
‪: Unused? And why is this public? Maybe align with zend-diactoros again

Definition at line 397 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 340 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 ( string  $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 146 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 ( string  $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 178 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 114 of file Message.php.

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

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

◆ 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 62 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 ( string  $name)

◆ isValidHeaderValue()

TYPO3\CMS\Core\Http\Message::isValidHeaderValue ( string  $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
Todo:
‪: Review. Should be protected / private, maybe align with zend-diactoros again

Definition at line 454 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 ( string  $name)

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

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

Definition at line 437 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 373 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 ( string  $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 238 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.

Returns
‪static
Exceptions

Definition at line 307 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 ( string  $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 202 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 ( string  $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 269 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 ( string  $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 80 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 = []
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 48 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 36 of file Message.php.

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