korolev icon indicating copy to clipboard operation
korolev copied to clipboard

Not working on korolev 1.3.0 + http4s 0.23.12

Open LMnet opened this issue 2 years ago • 3 comments

After updating from this set of dependencies:

val korolev = "1.2.0"
Seq(
  "org.typelevel" %% "cats-effect" % "2.5.1",
  "co.fs2" %% "fs2-core" % "2.5.6",
  "org.http4s" %% "http4s-blaze-server" % "0.21.1",
  "org.fomkin" %% "korolev-ce2" % korolev,
  "org.fomkin" %% "korolev-fs2-ce2" % korolev,
  "org.fomkin" %% "korolev-http4s" % korolev,
  "org.fomkin" %% "korolev-slf4j" % korolev,
)

To this:

val korolev = "1.3.0"
Seq(
  "org.typelevel" %% "cats-effect" % "3.3.12",
  "co.fs2" %% "fs2-core" % "3.2.8",
  "org.http4s" %% "http4s-blaze-server" % "0.23.12",
  "org.fomkin" %% "korolev-ce3" % korolev,
  "org.fomkin" %% "korolev-fs2-ce3" % korolev,
  "org.fomkin" %% "korolev-http4s" % korolev,
  "org.fomkin" %% "korolev-slf4j" % korolev,
)

My korolev application stops working. It loads all static and renders for the first time, but all interactive elements and events are not working.

In server logs I see this:

[INFO ] o.h.b.s.Http1ServerStage$$anon$1   Unknown connection header: 'Upgrade'. Closing connection upon completion.

I tried to investigate a bit. I found that in new version of http4s there is a new way of working with web sockets. WebSocketBuilder is deprecated in favor of WebSocketBuilder2 I tried to fix it locally, but after that my application starts to reload in an infinite cycle. I don't have enough knowledge of korolev internals to dive deeper, so I stopped there.

LMnet avatar Jun 20 '22 09:06 LMnet

Korolev gives a normal answer. But here is what I found in WebSocketBuilder2 code:

  private def buildResponse(webSocket: WebSocket[F]): F[Response[F]] =
    onNonWebSocketRequest
      .map(
        _.withAttribute(
          webSocketKey,
          WebSocketContext(
            webSocket,
            headers,
            onHandshakeFailure,
          ),
        )
      )

Wherein

 onNonWebSocketRequest =
        Response[F](Status.NotImplemented).withEntity("This is a WebSocket route.").pure[F],

It turns out that the builder itself immediately gives an error 501 to client.

morozov11 avatar Jun 20 '22 15:06 morozov11

Related issues from http4s:

  • https://github.com/http4s/http4s/issues/5542
  • https://github.com/http4s/blaze/issues/659

LMnet avatar Jun 21 '22 10:06 LMnet

Looks like this is the root cause: https://github.com/http4s/blaze/issues/659#issuecomment-1136426942

LMnet avatar Jun 21 '22 11:06 LMnet