-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
开启 HTTP2 时,$request->server['request_method'] 与 $request->getMethod() 的结果不一致。 #5400
Comments
如何复现? 我是这么验证的, 复现不了这种情况
准备包含swoole v6 的 swoole-clicurl https://github.com/jingjingxyk/swoole-cli/blob/new_dev/setup-swoole-cli-pre-runtime.sh?raw=true | bash
./bin/runtime/php -v
准备域名vi /etc/hosts
::1 http2-test.jingjingxyk.com
准备服务端<?php
use Swoole\Coroutine\Http\Server;
use function Swoole\Coroutine\run;
run(function () {
$server = new Server('::', 9502, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
$TLS_DIR = __DIR__;
$server->set([
'open_http2_protocol' => true,
'http2_enable_push' => 0x2,
'ssl_cert_file' => $TLS_DIR . '/wildcard.jingjingxyk.com.fullchain.pem',
'ssl_key_file' => $TLS_DIR . '/wildcard.jingjingxyk.com.key.pem',
'ssl_cafile' => __DIR__ . '/bin/runtime/cacert.pem',
'ssl_verify_peer' => true,
'ssl_protocols' => SWOOLE_SSL_TLSv1_3,
'log_level' => SWOOLE_LOG_TRACE,
'trace_flags' => SWOOLE_TRACE_ALL
]);
$server->handle('/', function ($request, $response) {
//var_dump($request);
var_dump($request->server['request_method']);
var_dump($request->getMethod());
$response->end("<h1>Index</h1>");
});
$server->handle('/api', function ($request, $response) {
//var_dump($request);
var_dump($request->server['request_method']);
var_dump($request->getMethod());
$response->end(json_encode($request, JSON_UNESCAPED_UNICODE));
});
$server->handle('/stop', function ($request, $response) use ($server) {
$response->end("<h1>Stop</h1>");
$server->shutdown();
});
$server->start();
});
客户端<?php
use Swoole\Http2\Request;
use Swoole\Coroutine\Http2\Client;
use function Swoole\Coroutine\run;
run(function () {
$domain = 'http2-test.jingjingxyk.com';
$cli = new Client($domain, 9502, true);
$cli->set([
'timeout' => -1,
'ssl_host_name' => $domain
]);
$cli->connect();
$req = new Request();
$req->method = 'POST';
$req->path = '/api';
$req->headers = [
'host' => $domain,
'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();
var_dump(json_decode($response->data));
});
|
server.php<?php
declare(strict_types=1);
use Swoole\Coroutine;
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;
require_once __DIR__ . '/../vendor/autoload.php';
Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);
$server = new Server('::', 443, SWOOLE_BASE, SWOOLE_SOCK_TCP6 | SWOOLE_SSL);
$server->set([
'reactor_num' => 1,
'worker_num' => 1,
'ssl_cert_file' => __DIR__ . '/../src/Resources/Ssl/realm.closure.cyou_bundle.crt',
'ssl_key_file' => __DIR__ . '/../src/Resources/Ssl/realm.closure.cyou.key',
'open_http2_protocol' => true,
]);
$server->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");
});
$server->start(); curl
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please answer these questions before submitting your issue.
一个简单的 HTTP 服务,提交一个 POST 表单。
What did you expect to see?
What did you see instead?
What version of Swoole are you using (show your
php --ri swoole
)?uname -a
&php -v
&gcc -v
) ?The text was updated successfully, but these errors were encountered: