From d0946c162cd56b48e755db0aa98ed9908dc00665 Mon Sep 17 00:00:00 2001 From: gaoolp Date: Mon, 21 Dec 2020 10:31:37 +0800 Subject: [PATCH] =?UTF-8?q?RPC=E6=94=AF=E6=8C=81header=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- src/RPC/RpcProxy.php | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 632e0e7..032d8d1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,7 @@ _book *.epub *.mobi *.pdf -*.idea \ No newline at end of file +*.idea + +vendor +composer.lock \ No newline at end of file diff --git a/src/RPC/RpcProxy.php b/src/RPC/RpcProxy.php index 962c8d0..9b1ebe9 100644 --- a/src/RPC/RpcProxy.php +++ b/src/RPC/RpcProxy.php @@ -3,6 +3,7 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; +use GuzzleHttp\Psr7\Request; use PhpBoot\Application; use PhpBoot\Controller\ControllerContainer; use PhpBoot\Controller\ControllerContainerBuilder; @@ -50,12 +51,17 @@ public function __call($method, $args) $request = $this->createRequest($method, $route, $args); + $options = [ + 'http_errors' => false, + 'headers' => $request->getHeaders(), + 'body' => $request->getBody() + ]; if(MultiRpc::isRunning()){ - $op = $this->http->sendAsync($request,['http_errors' => false]); + $op = $this->http->requestAsync($request->getMethod(), $request->getUri(), $options); $res = MultiRpc::wait($op); return $this->mapResponse($method, $route, $res, $args); }else{ - $res = $this->http->send($request,['http_errors' => false]); + $res = $this->http->request($request->getMethod(), $request->getUri(), $options); return $this->mapResponse($method, $route, $res, $args); } } @@ -64,7 +70,7 @@ public function __call($method, $args) * @param $actionName * @param Route $route * @param array $args - * @return RequestInterface + * @return Request */ public function createRequest($actionName, Route $route, array $args) { @@ -105,7 +111,10 @@ public function createRequest($actionName, Route $route, array $args) unset($request['query']); if(isset($request['headers'])){ - $headers += $request['headers']; + // 下划线转中划线,保持接口参数绑定一致 + foreach ($request['headers'] as $headerKey => $headerValue) { + $headers += [str_replace('_', '-', $headerKey) => $headerValue]; + } } unset($request['headers']);