Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add websocket support to Ktor cio #477

Open
jaffwu opened this issue Aug 24, 2020 · 2 comments
Open

Add websocket support to Ktor cio #477

jaffwu opened this issue Aug 24, 2020 · 2 comments

Comments

@jaffwu
Copy link

jaffwu commented Aug 24, 2020

No description provided.

@daviddenton
Copy link
Member

Feel free to PR it! It will be interesting to see if Ktor websockets fit into how we have modelled them! 😄

@waterbang
Copy link

Hi, I had originally intended to do it this way, but I couldn't find a place to return WsResponse. Does that mean I have to choose another engine instead? (For example, Netty) .

private val engine: CIOApplicationEngine = embeddedServer(CIO, port) {
        install(createApplicationPlugin(name = "http4k") {
          onCall {
            withContext(Default) {
              if (it.request.headers[HttpHeaders.Upgrade]?.equals("websocket",true) == true) {
               val wsResponse = it.request.asHttp4k()?.let(ws)
                // I can't construct the websocket returns
              } else {
                it.response.fromHttp4K(
                  it.request.asHttp4k()?.let(http) ?: Response(
                    NOT_IMPLEMENTED
                  )
                )
              }
            }
          }
        })
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants