apache / apache/brpc

brpc如何设置grpc-status和grpc-message?

Open
#1,207 7 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

brpc::Controller* cntl = static_cast(rpcCntl);
cntl->http_response().set_content_type("application/grpc");
cntl->http_response().set_status_code(200);
cntl->http_response().SetHeader("GRPC-STATUS", "6");
cntl->http_response().SetHeader("GRPC-MESSAGE", "Already exists");
response为
![image](https://user-images.githubusercontent.com/30468280/90233639-08d33c80-de51-11ea-89b2-ae155efbc3e2.png)
HyperText Transfer Protocol 2
Stream: HEADERS, Stream ID: 1, Length 63, 200 OK
Length: 63
Type: HEADERS (1)
Flags: 0x04
0... .... .... .... .... .... .... .... = Reserved: 0x0
.000 0000 0000 0000 0000 0000 0000 0001 = Stream Identifier: 1
[Pad Length: 0]
Header Block Fragment: 885f106170706c69636174696f6e2f67727063400b677270…
[Header Length: 108]
[Header Count: 4]
Header: :status: 200 OK
Header: content-type: application/grpc
Header: grpc-status: 6
Header: grpc-message: Already exists
Stream: DATA, Stream ID: 1, Length 5
Stream: HEADERS, Stream ID: 1, Length 4
Length: 4
Type: HEADERS (1)
Flags: 0x05
0... .... .... .... .... .... .... .... = Reserved: 0x0
.000 0000 0000 0000 0000 0000 0000 0001 = Stream Identifier: 1
[Pad Length: 0]
Header Block Fragment: 7f000130
[Header Length: 20]
[Header Count: 1]
Header: grpc-status: 0
Stream: WINDOW_UPDATE, Stream ID: 0, Length 4

brpc::Controller* cntl = static_cast(rpcCntl);
cntl->SetFailed(6, "Already exists");
cntl->http_response().set_content_type("application/grpc");
cntl->http_response().set_status_code(200);
cntl->http_response().SetHeader("GRPC-STATUS", "6");
cntl->http_response().SetHeader("GRPC-MESSAGE", "Already exists");
response为
![image](https://user-images.githubusercontent.com/30468280/90233819-489a2400-de51-11ea-8b8f-acd53726771a.png)
HyperText Transfer Protocol 2
Stream: HEADERS, Stream ID: 1, Length 63, 200 OK
Length: 63
Type: HEADERS (1)
Flags: 0x04
0... .... .... .... .... .... .... .... = Reserved: 0x0
.000 0000 0000 0000 0000 0000 0000 0001 = Stream Identifier: 1
[Pad Length: 0]
Header Block Fragment: 885f106170706c69636174696f6e2f67727063400b677270…
[Header Length: 108]
[Header Count: 4]
Header: :status: 200 OK
Header: content-type: application/grpc
Header: grpc-status: 6
Header: grpc-message: Already exists
Stream: DATA, Stream ID: 1, Length 5
Stream: HEADERS, Stream ID: 1, Length 79
Length: 79
Type: HEADERS (1)
Flags: 0x05
0... .... .... .... .... .... .... .... = Reserved: 0x0
.000 0000 0000 0000 0000 0000 0000 0001 = Stream Identifier: 1
[Pad Length: 0]
Header Block Fragment: 7f000231337f00472535622533312533372533322e253331…
[Header Length: 112]
[Header Count: 2]
Header: grpc-status: 13
Header: grpc-message: %5b%31%37%32.%31%37.%30.%32%3a%38%30%38%30%5d%5bE%36%5dAlready%20exists
Stream: WINDOW_UPDATE, Stream ID: 0, Length 4

brpc限定了grpc-status要么是0(ok),要么是13(internal error)?
请问可否自己设置grpc-status和grpc-message,该如何设置?

Contributor guide

Open the contributing guide

Research direction

Start with the brpc::Controller::SetFailed entry point and the http_response() header-setting calls shown in the issue, then trace how the gRPC response trailers are generated. Reproduce the request and compare the HTTP/2 captures; done means a caller-provided grpc-status and grpc-message are preserved instead of being replaced.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.