Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServerRequest nvalid header value #14150

Closed
cq-z opened this issue Jun 2, 2019 · 7 comments
Closed

ServerRequest nvalid header value #14150

cq-z opened this issue Jun 2, 2019 · 7 comments

Comments

@cq-z
Copy link
Contributor

cq-z commented Jun 2, 2019

Fatal error: Uncaught InvalidArgumentException: Invalid header value in phalcon/Http/Message/ServerRequest.zep:753
Stack trace:
#0 [internal function]: Phalcon\Http\Message\ServerRequest->checkHeaderValue(Array)
#1 [internal function]: Phalcon\Http\Message\ServerRequest->getHeaderValue(Array)
#2 xxxxx: Phalcon\Http\Message\ServerRequest->withAddedHeader('connection', 'keep-alive')
#3 {main}
thrown in phalcon/Http/Message/ServerRequest.zep on line 753

php code

$arr = [
    "host"=> "127.0.0.1:9000",
    "connection"=> "keep-alive",
    "pragma"=>"no-cache",
    "cache-control"=>"no-cache",
    "user-agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
    "dnt"=> "1",
    "accept"=>"image/webp,image/apng,image/*,*/*;q=0.8",
    "referer"=> "http://127.0.0.1:9000/",
    "accept-encoding"=> "gzip, deflate, br",
    "accept-language"=>"zh-CN,zh;q=0.9,en;q=0.8",
];
$ServerRequest = new \Phalcon\Http\Message\ServerRequest();
foreach($arr as $name=>$value ) {
    $ServerRequest->withAddedHeader($name,$value);
}

Details

php:7.3.4-fpm-alpine3.9
4.0.0-alpha.5

@cq-z
Copy link
Contributor Author

cq-z commented Jun 2, 2019

$ServerRequest->withAddedHeader($name,[$value]);
    $ServerRequest->withHeader($name,[$value]);

it is ok!

@zsilbi
Copy link
Member

zsilbi commented Jun 3, 2019

I couldn't reproduce this.

According to the code, ServerRequest->checkHeaderValue() should never get an array as parameter when called in getHeaderValue().
My best guess is that you may have compiled Phalcon with an older version of Zephir.

I tried this:

foreach ($arr as $name => $value) {
   $serverRequest = $serverRequest->withHeader($name, $value);
}

print_r($serverRequest->getHeaders());

and got everything as expected:

Array
(
    [host] => Array
        (
            [0] => 127.0.0.1:9000
        )

    [connection] => Array
        (
            [0] => keep-alive
        )
    ...

@cq-z
Copy link
Contributor Author

cq-z commented Jun 4, 2019

hi @zsilbi
you can run

docker run --rm -it 64899484/php bash -c "echo '<?php (new \Phalcon\Http\Message\ServerRequest())->withHeader(\"host\",\"127.0.0.1:9000\");' > test.php &&php test.php"

dockerfile

Exception

Fatal error: Uncaught InvalidArgumentException: Invalid header value in phalcon/Http/Message/ServerRequest.zep:753
Stack trace:
#0 [internal function]: Phalcon\Http\Message\ServerRequest->checkHeaderValue(Array)
#1 [internal function]: Phalcon\Http\Message\ServerRequest->getHeaderValue(Array)
#2 /data/www/test.php(1): Phalcon\Http\Message\ServerRequest->withHeader('host', '127.0.0.1:9000')
#3 {main}
  thrown in phalcon/Http/Message/ServerRequest.zep on line 753

@cq-z
Copy link
Contributor Author

cq-z commented Jun 4, 2019

Details

Phalcon version:4.0.0-alpha.5
php:7.3.4
System:alpine3.9

@Jeckerson
Copy link
Member

Jeckerson commented Jun 5, 2019

Currently this is fixed in 4.0.x branch and will enter to the next release.

UPD: After building image of @cq-z above with ENV PHALCON_VERSION=4.0.x and with link like that https://codeload.github.com/phalcon/cphalcon/tar.gz/v4.0x. It still get same error. However, compiling with Ubuntu and it worked...

@cq-z
Copy link
Contributor Author

cq-z commented Jun 7, 2019

So is this related to the gcc version?

@cq-z
Copy link
Contributor Author

cq-z commented Jul 22, 2019

4.0.0-beta.1 is ok ! thanks!

@cq-z cq-z closed this as completed Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants