connect does not notify the user when a websocket connection isn't upgraded
EthanLozano opened this issue · comments
Describe the bug
(Apologies in advance: I'm not sure which layer is potentially failing, or if I'm failing to interact with a layer properly. There is a good chance that this isn't a bug with websocket-kit)
WebSocket.connect
does not appear to notify the user if the server decides not to upgrade the request. Specifically, .whenFailure
is never triggered on the resulting EventLoopFuture.
To Reproduce
I'm using a vapor server, and my webSocket route defines a shouldUpgrade function that returns nil (under certain conditions):
shouldUpgrade: { req in
...
req.eventLoop.makeSucceededFuture(nil)
}
I believe that returning nil
is the correct use of the vapor API, but I also tried returning a failed future without any success:
req.eventLoop.makeFailedFuture(Abort(.forbidden))
On the client side, no code is triggered to alert the client that the upgrade failed
let result = WebSocket.connect(...)
result.whenFailure { error in
// not triggered
}
Expected behavior
I would expect .whenFailure
to be executed. Or, I would expect the API to support a closure for when the upgrade was rejected.
Environment
- Vapor websocket-kit: 2.1.2
- Vapor Framework version: 4.35.0
- Vapor Toolbox version: 18.0.0
- OS version: Mac OS 11.0.1 (20B50)
The root cause for this issue is vapor/vapor#2932.