Skip to content

Commit 006f870

Browse files
committed
Fixed #5400
1 parent 2f7ec2f commit 006f870

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

ext-src/swoole_http_request.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,13 @@ static PHP_METHOD(swoole_http_request, getMethod) {
988988
if (UNEXPECTED(!ctx)) {
989989
RETURN_FALSE;
990990
}
991-
const char *method = swoole_http_method_str((ctx->parser).method);
992-
RETURN_STRING(method);
991+
if (ctx->http2) {
992+
zval *zmethod = zend_hash_str_find(Z_ARR_P(ctx->request.zserver), ZEND_STRL("request_method"));
993+
RETURN_ZVAL(zmethod, 1, 0);
994+
} else {
995+
const char *method = swoole_http_method_str((ctx->parser).method);
996+
RETURN_STRING(method);
997+
}
993998
}
994999

9951000
static PHP_METHOD(swoole_http_request, isCompleted) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)