diff --git a/CHANGELOG.md b/CHANGELOG.md index e1332dc5..78c2abc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.5 + +* Set compressed flag correctly for grpc-encoding = identity. Fixes [#669](https://github.com/grpc/grpc-dart/issues/669) (https://github.com/grpc/grpc-dart/pull/693) + ## 3.2.4 * Forward internal `GrpcError` on when throwing while sending a request. diff --git a/lib/src/shared/message.dart b/lib/src/shared/message.dart index d9d64db1..0533c555 100644 --- a/lib/src/shared/message.dart +++ b/lib/src/shared/message.dart @@ -68,7 +68,8 @@ List frame(List rawPayload, [Codec? codec]) { final payloadLength = compressedPayload.length; final bytes = Uint8List(payloadLength + 5); final header = bytes.buffer.asByteData(0, 5); - header.setUint8(0, codec == null ? 0 : 1); + header.setUint8( + 0, (codec == null || codec.encodingName == 'identity') ? 0 : 1); header.setUint32(1, payloadLength); bytes.setRange(5, bytes.length, compressedPayload); return bytes; diff --git a/pubspec.yaml b/pubspec.yaml index a01ce0ec..e57074a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: grpc description: Dart implementation of gRPC, a high performance, open-source universal RPC framework. -version: 3.2.4 +version: 3.2.5 repository: https://github.com/grpc/grpc-dart diff --git a/test/grpc_compression_flag_test.dart b/test/grpc_compression_flag_test.dart new file mode 100644 index 00000000..adf2999a --- /dev/null +++ b/test/grpc_compression_flag_test.dart @@ -0,0 +1,26 @@ +import 'package:grpc/src/shared/codec.dart'; +import 'package:grpc/src/shared/message.dart'; +import 'package:test/test.dart'; + +void main() { + group('GRPC Compression Flag', () { + test('compression flag 0 with null codec', () { + final rawPayload = [1, 2, 3, 4]; + final Codec? codec = null; + final data = frame(rawPayload, codec); + expect(data[0], 0); + }); + test('compression flag 0 with grpc-encoding identity', () { + final rawPayload = [1, 2, 3, 4]; + final Codec codec = IdentityCodec(); + final data = frame(rawPayload, codec); + expect(data[0], 0); + }); + test('compression flag 1 with grpc-encoding gzip', () { + final rawPayload = [1, 2, 3, 4]; + final Codec codec = GzipCodec(); + final data = frame(rawPayload, codec); + expect(data[0], 1); + }); + }); +}