Skip to content

Websocket server returning 401; can't handle on client side #390

@chenfisher

Description

@chenfisher

I have a websocket server that returns 401 on the http handshake
I can't figure out how to get that information on the websocket client

Two things I can't figure out:

  1. Where can I get the http status code returned form the server (401 in this case)
    onClose is called but with irrelevant code (-1) which I saw in your code that it means "never connected"
  2. onError is called but for totally different reason. I get onError ssl == null
    why would the client library continue to try to decode the handshake, or something like that, when the socket wasn't upgraded (101)? why not just stop there? The ssl error is irrelevant here and is fired do to the fact that the server did not upgrade the socket

What I did to get the status code from the server was to subclass my own Draft, implement acceptHandshakeAsClient and copyInsance; this gave me access to the handshake response
When I see that the status code is 401 I return NOT_MATCHED
This is the only place I saw I can get the status code, but it makes me do ugly things like saving the status code in a variable to be used by onClose and onError which are then called (but with irrelevant data - code == -1 and error exception is ssl == null)

Thanks

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions