hyperf / hyperf/hyperf

RPC响应码非200即被T掉,需要进行优化。

Open
#1,783 5 comments 0 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.