Bug #88169
closedHeader value can have type int not string only.
0%
Description
File: /typo3/sysext/core/Classes/Http/Message.php
Function: withHeader($name, $value)
Lines: 201...218
In this function we can see next code:
if (!is_array($value) || !$this->arrayContainsOnlyStrings($value)) {
throw new \InvalidArgumentException('Invalid header value for header "' . $name . '"". The value must be a string or an array of strings.', 1436717266);
}
When I try this:
$file = BackendUtility::getRecord('sys_file', $id);
$response->withHeader('Content-Length', $file['size']);
I got exception: Invalid header value for header "Content-Length"". The value must be a string or an array of strings.
Yes, I know that I can convert int to the string. But int can be converted in string and I think this function should allow int values!
Updated by Susanne Moog over 5 years ago
- Status changed from New to Needs Feedback
Hey, thanks for your request.
I would prefer if TYPO3 did not convert things for me magically, but rather use what I add. Headers have to be string values (or array thereof) and I don't think TYPO3 should "fix" wrong code magically, as that promotes imho a wrong strategy.
Updated by Alexey Atsyn over 5 years ago
Susanne Moog wrote:
Hey, thanks for your request.
I would prefer if TYPO3 did not convert things for me magically, but rather use what I add. Headers have to be string values (or array thereof) and I don't think TYPO3 should "fix" wrong code magically, as that promotes imho a wrong strategy.
My mistake, I don't ask to convert int to the string. I try to allow int like correct value.
Content-Length should content integer value not a string!
Updated by Susanne Moog over 5 years ago
That is defined in the interface (PSR specification) which TYPO3 implements: https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php#L132 | https://www.php-fig.org/psr/psr-7/ see also the example at https://www.php-fig.org/psr/psr-7/meta/#what-if-i-just-want-to-return-a-file - I guess the PSR guys say "cast it to string".
Updated by Alexey Atsyn over 5 years ago
Susanne Moog wrote:
That is defined in the interface (PSR specification) which TYPO3 implements: https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php#L132 | https://www.php-fig.org/psr/psr-7/ see also the example at https://www.php-fig.org/psr/psr-7/meta/#what-if-i-just-want-to-return-a-file - I guess the PSR guys say "cast it to string".
OK, thx for explanation. Can be close.
Updated by Stephan Großberndt over 5 years ago
- Status changed from Needs Feedback to Closed