|
| 1 | +--TEST-- |
| 2 | +swoole_http2_server: getMethod |
| 3 | +--SKIPIF-- |
| 4 | +<?php require __DIR__ . '/../include/skipif.inc'; ?> |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +require __DIR__ . '/../include/bootstrap.php'; |
| 8 | +use Swoole\Http\Request; |
| 9 | +use Swoole\Http\Response; |
| 10 | +use Swoole\Http\Server; |
| 11 | + |
| 12 | +$pm = new ProcessManager; |
| 13 | +$pm->parentFunc = function ($pid) use ($pm) { |
| 14 | + go(function () use ($pm) { |
| 15 | + $cli = new Swoole\Coroutine\Http2\Client('127.0.0.1', $pm->getFreePort()); |
| 16 | + Assert::true($cli->connect()); |
| 17 | + $req = new Swoole\Http2\Request(); |
| 18 | + $req->method = 'POST'; |
| 19 | + $req->path = '/api'; |
| 20 | + $req->headers = [ |
| 21 | + 'user-agent' => 'Chrome/49.0.2587.3', |
| 22 | + 'accept' => 'text/html,application/xhtml+xml,application/xml', |
| 23 | + 'accept-encoding' => 'gzip' |
| 24 | + ]; |
| 25 | + $req->data = '{"type":"up"}'; |
| 26 | + $cli->send($req); |
| 27 | + $response = $cli->recv(); |
| 28 | + $json = json_decode($response->data); |
| 29 | + Assert::same($json->request_method, 'POST'); |
| 30 | + Assert::same($json->getMethod, 'POST'); |
| 31 | + $pm->kill(); |
| 32 | + }); |
| 33 | + Swoole\Event::wait(); |
| 34 | +}; |
| 35 | +$pm->childFunc = function () use ($pm) { |
| 36 | + $http = new Swoole\Http\Server('::', $pm->getFreePort(), SWOOLE_BASE, SWOOLE_SOCK_TCP6); |
| 37 | + $http->set([ |
| 38 | + 'worker_num' => 1, |
| 39 | + 'log_file' => '/dev/null', |
| 40 | + 'open_http2_protocol' => true |
| 41 | + ]); |
| 42 | + $http->on('workerStart', function ($serv, $wid) use ($pm) { |
| 43 | + $pm->wakeup(); |
| 44 | + }); |
| 45 | + $http->on('request', function (Request $request, Response $response) { |
| 46 | + $request_method = $request->server['request_method']; |
| 47 | + $getMethod = $request->getMethod(); |
| 48 | + $response->end(json_encode(compact('request_method', 'getMethod'), JSON_PRETTY_PRINT) . "\n"); |
| 49 | + }); |
| 50 | + $http->start(); |
| 51 | +}; |
| 52 | +$pm->childFirst(); |
| 53 | +$pm->run(); |
| 54 | +?> |
| 55 | +--EXPECT-- |
0 commit comments