From e94afcc70a61587117e2cf6146df0fc8b120f8ce Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 12 Apr 2021 16:43:49 +0300 Subject: [PATCH] dont fail empty payload Signed-off-by: Vasiliy Tolstov --- json/json.go | 6 +++++- proto/proto.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/json/json.go b/json/json.go index c9d3fca..2572491 100644 --- a/json/json.go +++ b/json/json.go @@ -85,7 +85,11 @@ func (c *jsonCodec) ReadBody(conn io.Reader, b interface{}) error { return nil } - return json.NewDecoder(conn).Decode(b) + err := json.NewDecoder(conn).Decode(b) + if err == io.EOF { + return nil + } + return err } func (c *jsonCodec) Write(conn io.Writer, m *codec.Message, b interface{}) error { diff --git a/proto/proto.go b/proto/proto.go index 991aec9..bce50d7 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -61,6 +61,8 @@ func (c *protoCodec) ReadBody(conn io.Reader, b interface{}) error { buf, err := ioutil.ReadAll(conn) if err != nil { return err + } else if buf == nil { + return nil } return proto.Unmarshal(buf, m) }