From 74e52bdb3edd9a5f918957eef9e192e30b95f5f5 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 | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/codec.go b/codec.go index 8de1b8b..dff9f60 100644 --- a/codec.go +++ b/codec.go @@ -93,10 +93,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 1113f84..874f727 100644 --- a/grpc.go +++ b/grpc.go @@ -203,9 +203,13 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) error { // get content type ct := defaultContentType + if ctype, ok := md["x-content-type"]; ok { ct = ctype } + if ctype, ok := md["content-type"]; ok { + ct = ctype + } delete(md, "x-content-type") delete(md, "timeout")