openswoole / ext-openswoole

Programmatic server for PHP with async IO, coroutines and fibers
https://openswoole.com
Apache License 2.0
808 stars 51 forks source link

[4.10] Http 2 Server does not support streaming #75

Closed Nek- closed 2 years ago

Nek- commented 3 years ago

Hello! Thanks for your work on swoole. I just tried it to make what I would hope a powerfull http/2 sse server but it didn't work at all. The reason is that it seems to be impossible to stream responses with swoole. Too bad!

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

I tried to stream a response by using the method Response::write().

  1. What did you expect to see?

Response streamed to user. No warning from swoole.

  1. What did you see instead?
Warning: Swoole\Http\Response::write(): HTTP2 client does not support HTTP-CHUNK in /.../router/vendor/hhxsv5/php-sse/src/SSESwoole.php on line 29
  1. What version of Open Swoole are you using (show your php --ri openswoole)?

4.7.2

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
$ php -v
PHP 8.0.10 (cli) (built: Aug 26 2021 15:50:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
  1. Location of the issue inside swoole codebase

https://github.com/openswoole/swoole-src/blob/8a581f572e6869e28bdf308d5640643ea6846172/ext-src/swoole_http_response.cc#L240-L245

doubaokun commented 2 years ago

According to RFC: https://greenbytes.de/tech/webdav/rfc7540.html#rfc.section.8.1.p.4

HTTP/2 uses DATA frames to carry message payloads. The chunked transfer encoding defined in Section 4.1 of [RFC7230] MUST NOT be used in HTTP/2.

The error message is updated to be more clear.

Nek- commented 2 years ago

@doubaokun does this means there's a way to stream responses with HTTP/2 and Swoole that is different? Didn't find anything in the documentation.

Nek- commented 2 years ago

@doubaokun are you saying SSE is not compatible with HTTP/2 ?

doubaokun commented 2 years ago

@Nek- it will be supported at the next release, PR https://github.com/openswoole/swoole-src/pull/125