From 387844fbc94eaccf4dbfa51efdba971fb760ebde Mon Sep 17 00:00:00 2001 From: Yurun Date: Fri, 6 Dec 2019 12:08:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20http2=20=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=B8=A6=20GET=20=E5=8F=82=E6=95=B0=20url=20=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/YurunHttp/Handler/Swoole.php | 12 +++++++++++- tests/server/Http2/http2-server.php | 8 ++++++++ tests/unit/Http2/SwooleHttp2Test.php | 27 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/YurunHttp/Handler/Swoole.php b/src/YurunHttp/Handler/Swoole.php index 63f943e..3bbeeff 100644 --- a/src/YurunHttp/Handler/Swoole.php +++ b/src/YurunHttp/Handler/Swoole.php @@ -150,7 +150,17 @@ public function buildRequest($request, $connection, &$http2Request) { $http2Request->headers = $headers; $http2Request->pipeline = $request->getAttribute(Attributes::HTTP2_PIPELINE, false); - $http2Request->path = $uri->getPath(); + $path = $uri->getPath(); + if('' === $path) + { + $path = '/'; + } + $query = $uri->getQuery(); + if('' !== $query) + { + $path .= '?' . $query; + } + $http2Request->path = $path; } else { diff --git a/tests/server/Http2/http2-server.php b/tests/server/Http2/http2-server.php index e6002bb..dc85f71 100644 --- a/tests/server/Http2/http2-server.php +++ b/tests/server/Http2/http2-server.php @@ -19,6 +19,14 @@ 'fd' => $request->fd, ])); break; + case '/get': + $response->header('trailer', 'yurun'); + $response->trailer('yurun', 'niubi'); + $response->end(json_encode([ + 'date' => $request->get['date'] ?? time(), + 'fd' => $request->fd, + ])); + break; case '/sleep': $data = json_decode($request->rawcontent(), true); Coroutine::sleep(1); diff --git a/tests/unit/Http2/SwooleHttp2Test.php b/tests/unit/Http2/SwooleHttp2Test.php index 588234a..a7f14ba 100644 --- a/tests/unit/Http2/SwooleHttp2Test.php +++ b/tests/unit/Http2/SwooleHttp2Test.php @@ -42,6 +42,33 @@ public function testHttp2() }); } + public function testHttp2ByUrl() + { + $this->call(function(){ + $http = new HttpRequest; + $http->protocolVersion = '2.0'; + $http->timeout = 3000; + + $date = strtotime('2017-03-24 17:12:14'); + $response = $http->post($this->http2Host . 'get?date=' . $date); + $data = $response->json(true); + $this->assertEquals($date, isset($data['date']) ? $data['date'] : null); + $this->assertGreaterThan(1, isset($data['fd']) ? $data['fd'] : null); + $this->assertEquals('yurun', $response->getHeaderLine('trailer')); + $this->assertEquals('niubi', $response->getHeaderLine('yurun')); + + $date = strtotime('2017-03-29 10:50:51'); + $response = $http->post($this->http2Host, [ + 'date' => $date, + ], 'json'); + $data2 = $response->json(true); + $this->assertEquals($date, isset($data2['date']) ? $data2['date'] : null); + $this->assertEquals($data['fd'], isset($data2['fd']) ? $data2['fd'] : null); + $this->assertEquals('yurun', $response->getHeaderLine('trailer')); + $this->assertEquals('niubi', $response->getHeaderLine('yurun')); + }); + } + public function testMuiltCo() { $this->call(function(){ From ca427be442e5aa4ad07e1dbb74bc7c7552d84486 Mon Sep 17 00:00:00 2001 From: Yurun Date: Fri, 6 Dec 2019 13:09:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20travis=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=94=AF=E6=8C=81=20php=207.4=20=E6=AD=A3=E5=BC=8F?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e28342..29ac16e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,20 +24,21 @@ matrix: env: SWOOLE_VERSION="v4.4.12" - php: '7.3' env: SWOOLE_VERSION="v4.4.12" + - php: '7.4' + env: SWOOLE_VERSION="v4.4.12" - php: '7.1' env: SWOOLE_VERSION="master" - php: '7.2' env: SWOOLE_VERSION="master" - php: '7.3' env: SWOOLE_VERSION="master" - - php: '7.4snapshot' - env: SWOOLE_VERSION="master" DISABLE_XDEBUG=false PHPUNIT_VERSION="7" + - php: '7.4' + env: SWOOLE_VERSION="master" - php: 'nightly' env: SWOOLE_VERSION="master" DISABLE_XDEBUG=false PHPUNIT_VERSION="7" INSTALL_REDIS_EXT=true allow_failures: - env: SWOOLE_VERSION="master" - php: nightly - - php: 7.4snapshot env: global: