RPC响应码非200即被T掉,需要进行优化。
- Dominant language
- PHP
- Stars
- 6.9k
- Forks
- 1.3k
- Avg merge
- 4h 21m
- Merged PRs (30d)
- 4
Description
hyperf/json-rpc/src/JsonRpcHttpTransporter.php
``` public function send(string $data)
{
$node = $this->getNode();
$uri = $node->host . ':' . $node->port;
$schema = value(function () use ($node) {
$schema = 'http';
if (property_exists($node, 'schema')) {
$schema = $node->schema;
}
if (! in_array($schema, ['http', 'https'])) {
$schema = 'http';
}
$schema .= '://';
return $schema;
});
$url = $schema . $uri;
$response = $this->getClient()->post($url, [
'headers' => [
'Content-Type' => 'application/json',
],
'http_errors' => false,
'body' => $data,
]);
if ($response->getStatusCode() === 200) {
return $response->getBody()->getContents();
}
$this->loadBalancer->removeNode($node);
return '';
}
```
响应码 [200, 300) 应该都是合理的,另外如果用户的错误码规范完全遵循HTTP规范,即如果数据不存在,会返回 404,这种情况也需要被考虑。
Contributor guide
Assessment
This issue has not been assessed yet.