MockWebServer: Support closing WebSocket with codes 1005 or 1006
I'm using MockWebServer to test a WebSocket client which should be able to gracefully deal with an scenario where the server closes the connection without a status code (1005) or doesn't send a close frame at all (1006).
I'd expect to be able to call websocket.close() to replicate the former, but WebSocket.close() requires a code. But if I set 1005, OkHTTP rejects it (as it should per the spec). That means I don't have a way to replicate a 1005.
On the other hand, I'd expect to be able to replicate a 1006 by calling websocket.cancel(). However, I get a NullPointerException because RealWebSocket.cancel() seems to be reserved for client sockets:
https://github.com/square/okhttp/blob/9ee33446f83932a2bb001e5ef2156a3d5de5838d/okhttp/src/main/kotlin/okhttp3/internal/ws/RealWebSocket.kt#L70-L71 https://github.com/square/okhttp/blob/9ee33446f83932a2bb001e5ef2156a3d5de5838d/okhttp/src/main/kotlin/okhttp3/internal/ws/RealWebSocket.kt#L142-L144