fix grpc json streaming by setting content sub type (#1089)

This commit is contained in:
Asim Aslam 2020-01-07 18:37:34 +00:00 committed by Vasiliy Tolstov
parent 7d5e31cd58
commit 8c86ad526f
2 changed files with 4 additions and 2 deletions

View File

@ -116,10 +116,12 @@ func (jsonCodec) Marshal(v interface{}) ([]byte, error) {
} }
func (jsonCodec) Unmarshal(data []byte, v interface{}) error { func (jsonCodec) Unmarshal(data []byte, v interface{}) error {
if len(data) == 0 {
return nil
}
if pb, ok := v.(proto.Message); ok { if pb, ok := v.(proto.Message); ok {
return jsonpb.Unmarshal(b.NewReader(data), pb) return jsonpb.Unmarshal(b.NewReader(data), pb)
} }
return json.Unmarshal(data, v) return json.Unmarshal(data, v)
} }

View File

@ -207,7 +207,7 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client
ServerStreams: true, ServerStreams: true,
} }
grpcCallOptions := []grpc.CallOption{} grpcCallOptions := []grpc.CallOption{grpc.CallContentSubtype(cf.Name())}
if opts := g.getGrpcCallOptions(); opts != nil { if opts := g.getGrpcCallOptions(); opts != nil {
grpcCallOptions = append(grpcCallOptions, opts...) grpcCallOptions = append(grpcCallOptions, opts...)
} }