Upgrade request to WebSocket #168
-
Great work on reaching v1.0.0. I have been interested in this project for some time now. I wanted to ask if it is possible to programmatically upgrade a GET request to WebSocket instead of declaring a separate route for WebSocket? I am looking to do something similar to Vapor's I have a use case where a HTTP GET route may respond differently depending on the search parameters (query variables) and headers, one of the response may be a WebSocket switching protocol. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There is no way to programmatically do it at the moment, but each WebSocket upgrade has a |
Beta Was this translation helpful? Give feedback.
There is no way to programmatically do it at the moment, but each WebSocket upgrade has a
shouldUpgrade
closure where you can make a decision on whether the path should upgrade to WebSockets. If you don't want to upgrade you can throw an error. You can control how that error is serialised as an HTTP reponse by conforming it to theHBHTTPErrorResponse
protocol. If this isn't enough please add an issue to the websocket repo.