Project

General

Profile

Actions

Bug #88169

closed

Header value can have type int not string only.

Added by Alexey Atsyn over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2019-04-18
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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!

Actions #1

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.

Actions #2

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!

Actions #3

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".

Actions #4

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.

Actions #5

Updated by Stephan Großberndt over 5 years ago

  • Status changed from Needs Feedback to Closed
Actions

Also available in: Atom PDF