Encode server error message (#330)

This commit is contained in:
Koichi Ishida 2020-07-24 17:20:23 +09:00 committed by GitHub
parent 98ff843751
commit e4947e2909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -293,7 +293,8 @@ class ServerHandler_ extends ServiceCall {
_customTrailers = null;
outgoingTrailersMap['grpc-status'] = status.toString();
if (message != null) {
outgoingTrailersMap['grpc-message'] = message;
outgoingTrailersMap['grpc-message'] =
Uri.encodeFull(message).replaceAll("%20", " ");
}
final outgoingTrailers = <Header>[];

View File

@ -167,6 +167,20 @@ void main() {
await harness.fromServer.done;
});
test('Server returns encoded error for unary call', () async {
Future<int> methodHandler(ServiceCall call, Future<int> request) async {
throw GrpcError.unknown("エラー");
}
harness
..service.unaryHandler = methodHandler
..expectErrorResponse(StatusCode.unknown, '%E3%82%A8%E3%83%A9%E3%83%BC')
..sendRequestHeader('/Test/Unary')
..sendData(dummyValue)
..toServer.close();
await harness.fromServer.done;
});
test('Server returns error if multiple headers are received for unary call',
() async {
harness