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.
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.