I'm not sure if this suggestion is a good one, but given that dispatch() is just about routing I'm inclined to call handle_ping() directly and reduce the code that has to be involved in making it work properly.