From 2f3869c451afcda042df847981d61e32dd609626 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 23 Mar 2018 00:41:28 +0900 Subject: [PATCH] ing --- protocol/json/server_request.go | 6 +++++- protocol/server_codec.go | 1 + servlet.go | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/protocol/json/server_request.go b/protocol/json/server_request.go index 636863c..9f0d955 100644 --- a/protocol/json/server_request.go +++ b/protocol/json/server_request.go @@ -73,6 +73,10 @@ type ServerRequestCodec struct { codec codec.Codec } +func (src *ServerRequestCodec) HasResponse() bool { + return src.req.ID != nil +} + // Method returns the RPC method for the current request. // // The method uses a dotted notation as in "Service.Method". @@ -149,7 +153,7 @@ func (src *ServerRequestCodec) WriteError(w io.Writer, status int, err error) er func (src *ServerRequestCodec) writeServerResponse(w io.Writer, res *serverResponse) error { // ID is null for notifications and they don't have a response. - if res.ID != nil { + if src.req.ID != nil { encoder := json.NewEncoder(src.codec.Encode(w)) // Not sure in which case will this happen. But seems harmless. if err := encoder.Encode(res); nil != err { diff --git a/protocol/server_codec.go b/protocol/server_codec.go index 92f98de..219af30 100644 --- a/protocol/server_codec.go +++ b/protocol/server_codec.go @@ -15,6 +15,7 @@ type ServerCodec interface { type ServerRequestCodec interface { RegistryCodec + HasResponse() bool WriteResponse(w io.Writer, reply interface{}) error WriteError(w io.Writer, status int, err error) error } diff --git a/servlet.go b/servlet.go index 068b203..7317842 100644 --- a/servlet.go +++ b/servlet.go @@ -239,6 +239,10 @@ func handleRequest(s *rpcServlet, requestCodec protocol.ServerRequestCodec) { result, err := s.sh.Invoke(s.ctx, requestCodec) + if !requestCodec.HasResponse() { + return + } + rs := &responseState{ requestCodec: requestCodec, result: result,