-
-
Notifications
You must be signed in to change notification settings - Fork 14
Propagate response headers with grpc error metadata #32
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df5b64b
Improve handling grpc response headers, propagate response headers wi…
rauanmayemir cfbad5a
Add response trailers
rauanmayemir c593a03
Do not add empty headers/trailers
rauanmayemir a7e813f
Add type-hint for grpc payload header
rauanmayemir 1276246
Address code review suggestions
rauanmayemir 4c1bcab
Set RR constraint to ^2024.3
rauanmayemir 5a6ea30
Add test coverage for invoke exception with outgoing headers and trai…
rauanmayemir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <files psalm-version="dev-master@765dcbfe43002e52e4808b65561842784fe7bcc7"/> | ||
| <files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Spiral\RoadRunner\GRPC\Internal; | ||
|
|
||
| use Spiral\RoadRunner\GRPC\ServiceInterface; | ||
|
|
||
| /** | ||
| * @internal | ||
| * @psalm-internal Spiral\RoadRunner\GRPC | ||
| */ | ||
| final class CallContext | ||
| { | ||
| /** | ||
| * @param class-string<ServiceInterface> $service | ||
| * @param non-empty-string $method | ||
| * @param array<string, array<string>> $context | ||
| */ | ||
| public function __construct( | ||
| public readonly string $service, | ||
| public readonly string $method, | ||
| public readonly array $context, | ||
| ) {} | ||
|
|
||
| /** | ||
| * @throws \JsonException | ||
| */ | ||
| public static function decode(string $payload): self | ||
| { | ||
| /** | ||
| * @psalm-var array{ | ||
| * service: class-string<ServiceInterface>, | ||
| * method: non-empty-string, | ||
| * context: array<string, array<string>> | ||
| * } $data | ||
| */ | ||
| $data = Json::decode($payload); | ||
|
|
||
| return new self( | ||
| service: $data['service'], | ||
| method: $data['method'], | ||
| context: $data['context'], | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Spiral\RoadRunner\GRPC; | ||
|
|
||
| use Spiral\RoadRunner\GRPC\Internal\Json; | ||
|
|
||
| /** | ||
| * @psalm-type THeaderKey = non-empty-string | ||
| * @psalm-type THeaderValue = string | ||
| * @implements \IteratorAggregate<THeaderKey, string> | ||
| */ | ||
| final class ResponseTrailers implements \IteratorAggregate, \Countable | ||
| { | ||
| /** | ||
| * @var array<THeaderKey, THeaderValue> | ||
| */ | ||
| private array $trailers = []; | ||
|
|
||
| /** | ||
| * @param iterable<THeaderKey, THeaderValue> $trailers | ||
| */ | ||
| public function __construct(iterable $trailers = []) | ||
| { | ||
| foreach ($trailers as $key => $value) { | ||
| $this->set($key, $value); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param THeaderKey $key | ||
| * @param THeaderValue $value | ||
| */ | ||
| public function set(string $key, string $value): void | ||
| { | ||
| $this->trailers[$key] = $value; | ||
| } | ||
|
|
||
| /** | ||
| * @param THeaderKey $key | ||
| * @return THeaderValue|null | ||
| */ | ||
| public function get(string $key, ?string $default = null): ?string | ||
| { | ||
| return $this->trailers[$key] ?? $default; | ||
| } | ||
|
|
||
| public function getIterator(): \Traversable | ||
| { | ||
| return new \ArrayIterator($this->trailers); | ||
| } | ||
|
|
||
| public function count(): int | ||
| { | ||
| return \count($this->trailers); | ||
| } | ||
|
|
||
| /** | ||
| * @throws \JsonException | ||
| */ | ||
| public function packTrailers(): string | ||
| { | ||
| // If an empty array is serialized, it is cast to the string "[]" | ||
| // instead of object string "{}" | ||
| if ($this->trailers === []) { | ||
| return '{}'; | ||
| } | ||
|
|
||
| return Json::encode($this->trailers); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.