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

Array to string conversion error for HTTP/2 headers #4133

Closed
gwilym opened this issue Apr 7, 2021 · 1 comment
Closed

Array to string conversion error for HTTP/2 headers #4133

gwilym opened this issue Apr 7, 2021 · 1 comment
Labels

Comments

@gwilym
Copy link

gwilym commented Apr 7, 2021

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.

This is related to a fix in LaravelS: hhxsv5/laravel-s#341

Based on https://wiki.swoole.com/#/http_server?id=setheader we try to use an array type for header values, but it emits an error under HTTP/2.

Test script (foo.php):

<?php

$http = new Swoole\Http\Server("127.0.0.1", 9501);
$http->set(['open_http2_protocol' => true]);

$http->on('request', function ($request, $response) {
    $response->header('Test-Value', [
        "a\r\n",
        'd5678',
        "e  \n ",
        null,
        5678,
        3.1415926,
    ]);

    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
$http->start();
  1. What did you expect to see?

Multiple headers with no error, such as this:

$ curl -v http://localhost:9501
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9501 (#0)
> GET / HTTP/1.1
> Host: localhost:9501
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Test-Value: a
< Test-Value: d5678
< Test-Value: e
< Test-Value: 5678
< Test-Value: 3.1415926
< Server: swoole-http-server
< Connection: keep-alive
< Content-Type: text/html
< Date: Wed, 07 Apr 2021 06:55:36 GMT
< Content-Length: 28
<
* Connection #0 to host localhost left intact
<h1>Hello Swoole. #8020</h1>* Closing connection 0
  1. What did you see instead?

A single header with value Array:

$ curl --http2-prior-knowledge -v http://localhost:9501
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9501 (#0)
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fdc0e80d600)
> GET / HTTP/2
> Host: localhost:9501
> User-Agent: curl/7.64.1
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200
< test-value: Array
< server: swoole-http-server
< date: Wed, 07 Apr 2021 06:55:43 GMT
< content-type: text/html
< content-length: 28
<
* Connection #0 to host localhost left intact
<h1>Hello Swoole. #1940</h1>* Closing connection 0

And an error logged in the PHP console:

PHP Notice:  Array to string conversion in $DIR/foo.php on line 16

Notice: Array to string conversion in $DIR/foo.php on line 16
  1. What version of Swoole are you using (show your php --ri swoole)?

4.6.3 and 4.6.4

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

Darwin C02CN25XMD6P 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64

PHP 7.4.16 (cli) (built: Mar 4 2021 20:49:25) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.26.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Problem also exhibits in a separate Debian-based container environment.

matyhtf added a commit that referenced this issue Apr 9, 2021
* Allow array HTTP/2 headers, Bug fixed for #4133

* Fix tests

* Fix tests

* Fix tests

* optimize

Co-authored-by: matyhtf <mikan.tenny@gmail.com>
@matyhtf
Copy link
Member

matyhtf commented Apr 9, 2021

46ea525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants