ing
This commit is contained in:
parent
2423b22685
commit
2f3869c451
|
@ -73,6 +73,10 @@ type ServerRequestCodec struct {
|
||||||
codec codec.Codec
|
codec codec.Codec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (src *ServerRequestCodec) HasResponse() bool {
|
||||||
|
return src.req.ID != nil
|
||||||
|
}
|
||||||
|
|
||||||
// Method returns the RPC method for the current request.
|
// Method returns the RPC method for the current request.
|
||||||
//
|
//
|
||||||
// The method uses a dotted notation as in "Service.Method".
|
// 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 {
|
func (src *ServerRequestCodec) writeServerResponse(w io.Writer, res *serverResponse) error {
|
||||||
// ID is null for notifications and they don't have a response.
|
// 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))
|
encoder := json.NewEncoder(src.codec.Encode(w))
|
||||||
// Not sure in which case will this happen. But seems harmless.
|
// Not sure in which case will this happen. But seems harmless.
|
||||||
if err := encoder.Encode(res); nil != err {
|
if err := encoder.Encode(res); nil != err {
|
||||||
|
|
|
@ -15,6 +15,7 @@ type ServerCodec interface {
|
||||||
type ServerRequestCodec interface {
|
type ServerRequestCodec interface {
|
||||||
RegistryCodec
|
RegistryCodec
|
||||||
|
|
||||||
|
HasResponse() bool
|
||||||
WriteResponse(w io.Writer, reply interface{}) error
|
WriteResponse(w io.Writer, reply interface{}) error
|
||||||
WriteError(w io.Writer, status int, err error) error
|
WriteError(w io.Writer, status int, err error) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,6 +239,10 @@ func handleRequest(s *rpcServlet, requestCodec protocol.ServerRequestCodec) {
|
||||||
|
|
||||||
result, err := s.sh.Invoke(s.ctx, requestCodec)
|
result, err := s.sh.Invoke(s.ctx, requestCodec)
|
||||||
|
|
||||||
|
if !requestCodec.HasResponse() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
rs := &responseState{
|
rs := &responseState{
|
||||||
requestCodec: requestCodec,
|
requestCodec: requestCodec,
|
||||||
result: result,
|
result: result,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user