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: 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(){