Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockWebServer: Support closing WebSocket with codes 1005 or 1006 #6333

Open
gnarea opened this issue Oct 21, 2020 · 0 comments
Open

MockWebServer: Support closing WebSocket with codes 1005 or 1006 #6333

gnarea opened this issue Oct 21, 2020 · 0 comments
Labels
enhancement Feature not a bug mockwebserver MockWebServer related

Comments

@gnarea
Copy link

gnarea commented Oct 21, 2020

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:

/** Non-null for client web sockets. These can be canceled. */
private var call: Call? = null

override fun cancel() {
call!!.cancel()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature not a bug mockwebserver MockWebServer related
Projects
None yet
Development

No branches or pull requests

2 participants