Building42 / Telegraph

Secure Web Server for iOS, tvOS and macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSocket disconnected, error: The handshake request failed with status 101 Web Socket Protocol Handshake

henryhenryhenry3 opened this issue · comments

extension HTTPStatus {
  public static func == (lhs: HTTPStatus, rhs: HTTPStatus) -> Bool {
    return lhs.code == rhs.code && lhs.phrase == rhs.phrase
  }
}

static let switchingProtocols = HTTPStatus(code: 101, phrase: "Switching Protocols")

But some other Websocket Server (like Java-WebSocket) returned
code:101, phrase:"Web Socket Protocol Handshake"

So the Telegraph client can not connect to this server.
The handshake request failed with status 101 Web Socket Protocol Handshake

That error would indicate that the Telegraph client didn't accept the WebSocket server's handshake. That might be caused by an invalid header or otherwise invalid HTTPResponse.

Do you have a small example app for me to replicate the issue?
Or a quick way that I can run the Java-WebSocket server myself?

That error would indicate that the Telegraph client didn't accept the WebSocket server's handshake. That might be caused by an invalid header or otherwise invalid HTTPResponse.

Do you have a small example app for me to replicate the issue?
Or a quick way that I can run the Java-WebSocket server myself?

I replaced:

extension HTTPStatus {
  public static func == (lhs: HTTPStatus, rhs: HTTPStatus) -> Bool {
    return lhs.code == rhs.code && lhs.phrase == rhs.phrase
  }
}

with:

extension HTTPStatus {
  public static func == (lhs: HTTPStatus, rhs: HTTPStatus) -> Bool {
    return lhs.code == rhs.code
  }
}

works well :-)

Ah that is interesting, the handshake was rejected because the HTTPStatus phrases are different: "Switching Protocols" != "Web Socket Protocol Handshake"

A few minutes ago I've pushed a commit that improves the Equatable implementation of HTTPStatus. Now by default two HTTPStatus values are compared by code unless they are created with strict: true.

Can you try the master branch for me in your project?

@henryhenryhenry3 Did the latest code on the master branch resolve your issue?
If so, I'll publish it under a new version.