Skip to content

Commit

Permalink
Fixed #5400
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jul 18, 2024
1 parent 142fb27 commit 6e0b20f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ext-src/swoole_http_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,13 @@ static PHP_METHOD(swoole_http_request, getMethod) {
if (UNEXPECTED(!ctx)) {
RETURN_FALSE;
}
const char *method = swoole_http_method_str((ctx->parser).method);
RETURN_STRING(method);
if (ctx->http2) {
zval *zmethod = zend_hash_str_find(Z_ARR_P(ctx->request.zserver), ZEND_STRL("request_method"));
RETURN_ZVAL(zmethod, 1, 0);
} else {
const char *method = swoole_http_method_str((ctx->parser).method);
RETURN_STRING(method);
}
}

static PHP_METHOD(swoole_http_request, isCompleted) {
Expand Down
55 changes: 55 additions & 0 deletions tests/swoole_http2_server/getMethod.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
swoole_http2_server: getMethod
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

$pm = new ProcessManager;
$pm->parentFunc = function ($pid) use ($pm) {
go(function () use ($pm) {
$cli = new Swoole\Coroutine\Http2\Client('127.0.0.1', $pm->getFreePort());
Assert::true($cli->connect());
$req = new Swoole\Http2\Request();
$req->method = 'POST';
$req->path = '/api';
$req->headers = [
'user-agent' => 'Chrome/49.0.2587.3',
'accept' => 'text/html,application/xhtml+xml,application/xml',
'accept-encoding' => 'gzip'
];
$req->data = '{"type":"up"}';
$cli->send($req);
$response = $cli->recv();
$json = json_decode($response->data);
Assert::same($json->request_method, 'POST');
Assert::same($json->getMethod, 'POST');
$pm->kill();
});
Swoole\Event::wait();
};
$pm->childFunc = function () use ($pm) {
$http = new Swoole\Http\Server('::', $pm->getFreePort(), SWOOLE_BASE, SWOOLE_SOCK_TCP6);
$http->set([
'worker_num' => 1,
'log_file' => '/dev/null',
'open_http2_protocol' => true
]);
$http->on('workerStart', function ($serv, $wid) use ($pm) {
$pm->wakeup();
});
$http->on('request', function (Request $request, Response $response) {
$request_method = $request->server['request_method'];
$getMethod = $request->getMethod();
$response->end(json_encode(compact('request_method', 'getMethod'), JSON_PRETTY_PRINT) . "\n");
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--

0 comments on commit 6e0b20f

Please sign in to comment.