Hi, I am trying to simulate a Rails backend offeri...
# http4k
h
Hi, I am trying to simulate a Rails backend offering a websocket endpoint with the subprotocol "actioncable-v1-json". For this to work, the response to the upgradeRequest has to contain the header "Sec-WebSocket-Protocol: actioncable-v1-json". Unfortunately, I haven't found an official way to tell the Jetty server to accept this protocol. What works, though, is using a cloned version of the Jetty-PolyServerConfig implementation using a modified
WsHandler.toJettyNegotiator()
function with one line added before line 44 in jettyInfra.kt https://github.com/http4k/http4k/blob/master/http4k-server/jetty/src/main/kotlin/org/http4k/server/jettyInfra.kt#L44
Copy code
fun WsHandler.toJettyNegotiator() = object : WebSocketNegotiator.AbstractNegotiator() {
    override fun negotiate(negotiation: WebSocketNegotiation): FrameHandler {
        negotiation.subprotocol = "actioncable-v1-json"         // the added line
        val request = negotiation.request.asHttp4kRequest()!!
        return Http4kWebSocketFrameHandler(this@toJettyNegotiator(request), request)
    }
}
Is there a more elegant alternative to that? Maybe using another server backend?
d
At the moment, this is totally new, so there isn't really a better way. But it is something we do need to account for. If you could add a GitHub issue that would be amazing so at least we can track it (we also need to work out what happens with the other websocket implementations 🙂 )
h
Thanks for your quick reply, here it is: https://github.com/http4k/http4k/issues/885