From 8c86ad526fc9dbff3f873c97e9236bc8763c9867 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Jan 2020 18:37:34 +0000 Subject: [PATCH] fix grpc json streaming by setting content sub type (#1089) --- codec.go | 4 +++- grpc.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/codec.go b/codec.go index 44f16d5..70ef0b9 100644 --- a/codec.go +++ b/codec.go @@ -116,10 +116,12 @@ func (jsonCodec) Marshal(v interface{}) ([]byte, error) { } func (jsonCodec) Unmarshal(data []byte, v interface{}) error { + if len(data) == 0 { + return nil + } if pb, ok := v.(proto.Message); ok { return jsonpb.Unmarshal(b.NewReader(data), pb) } - return json.Unmarshal(data, v) } diff --git a/grpc.go b/grpc.go index e8e23a3..3d158ea 100644 --- a/grpc.go +++ b/grpc.go @@ -207,7 +207,7 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client ServerStreams: true, } - grpcCallOptions := []grpc.CallOption{} + grpcCallOptions := []grpc.CallOption{grpc.CallContentSubtype(cf.Name())} if opts := g.getGrpcCallOptions(); opts != nil { grpcCallOptions = append(grpcCallOptions, opts...) }