Merge branch 'hotfix/insert-timeout-header' into 'master'

Hotfix/insert timeout header

See merge request composer/php-json-rpc!2
This commit is contained in:
候学杰 2019-03-11 16:07:04 +08:00
commit 47edd9968b

View File

@ -63,7 +63,7 @@ class Client extends JsonRpc
* @throws RpcServerException * @throws RpcServerException
* @return array * @return array
*/ */
public function call($name, $arguments) public function call($name, $arguments, $options = [])
{ {
$payload = [ $payload = [
'jsonrpc' => '2.0', 'jsonrpc' => '2.0',
@ -71,7 +71,7 @@ class Client extends JsonRpc
'params' => $arguments, 'params' => $arguments,
'id' => $this->id(), 'id' => $this->id(),
]; ];
return $this->post($payload); return $this->post($payload, $options);
} }
/** /**
@ -90,17 +90,17 @@ class Client extends JsonRpc
* @throws RpcServerException * @throws RpcServerException
* @return array * @return array
*/ */
protected function post($payload) protected function post($payload, $options = [])
{ {
try { try {
$headers = [ $headers = [
'X-Client-App' => $this->config['app'], 'X-Client-App' => $this->config['app'],
]; ];
app('rpc.logger')->info("client_request", array_merge($this->server_config, $payload)); app('rpc.logger')->info("client_request", array_merge($this->server_config, $payload));
$resp = $this->http->request('POST', 'rpc/json-rpc-v2.json', [ $resp = $this->http->request('POST', 'rpc/json-rpc-v2.json', array_merge([
'headers' => $headers, 'headers' => $headers,
'json' => $payload, 'json' => $payload,
]); ], $options));
} catch (ServerException $e) { } catch (ServerException $e) {
$ex = new RpcServerException(self::ErrorMsg[JsonRpc::Rpc_Error_Internal_Error], JsonRpc::Rpc_Error_Internal_Error); $ex = new RpcServerException(self::ErrorMsg[JsonRpc::Rpc_Error_Internal_Error], JsonRpc::Rpc_Error_Internal_Error);
if (env("APP_DEBUG") == true) { if (env("APP_DEBUG") == true) {