sourcegraph / jsonrpc2

Package jsonrpc2 provides a client and server implementation of JSON-RPC 2.0 (http://www.jsonrpc.org/specification)
MIT License
195 stars 62 forks source link

Fix logging of received response messages #71

Closed fhs closed 1 year ago

fhs commented 1 year ago

As documented: OnRecv causes all requests received on conn to invoke f(req, nil) and all responses to invoke f(req, resp).

Since OnRecv is called with both Request and Response being non-nil when we're handling a response, we need to check that Response is non-nil before we check Request is non-nil. This change just swaps the two cases in the switch statement to fix the issue. For consistency, I've swapped the cases for OnSend also, even when it's not needed.