#88169Header value can have type int not string only.
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!
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 6
-
Susanne Moog commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2019-04-18T09:23:48+00:00" > 04/18/19, 09:23 </span> -
Alexey Atsyn commented <span data-processor="relativetime" data-value="2019-04-18T09:35:31+00:00" > 04/18/19, 09:35 </span>
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! -
Susanne Moog commented <span data-processor="relativetime" data-value="2019-04-18T10:29:32+00:00" > 04/18/19, 10:29 </span>
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”.
-
Alexey Atsyn commented <span data-processor="relativetime" data-value="2019-04-18T10:33:32+00:00" > 04/18/19, 10:33 </span>
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.
-
Stephan Großberndt changed status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2019-04-18T10:56:57+00:00" > 04/18/19, 10:56 </span> -
Mathias Brodala commented <span data-processor="relativetime" data-value="2026-05-21T13:01:23+00:00" > 05/21/26, 13:01 </span>
Anyone who ends up here with an exception like this make sure to update Guzzle to version 7.10.2 or newer.
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.