Skip to content

Commit

Permalink
Merge pull request #3068 from kamilkloch/websockets
Browse files Browse the repository at this point in the history
Simplify http4s websocket interpreter.
  • Loading branch information
adamw authored Jul 25, 2023
2 parents 9359d82 + 09e9b45 commit 5aa112d
Showing 1 changed file with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,17 @@ trait Http4sServerInterpreter[F[_]] {

response.body match {
case Some(Left(pipeF)) =>
Queue.bounded[F, WebSocketFrame](32).flatMap { queue =>
pipeF.flatMap { pipe =>
val send: Stream[F, WebSocketFrame] = Stream.repeatEval(queue.take)
val receive: Pipe[F, WebSocketFrame, Unit] = pipe.andThen(s => s.evalMap(f => queue.offer(f)))
webSocketBuilder match {
case Some(wsb) => wsb.withHeaders(headers).build(send, receive)
case None =>
monad.error(
new Http4sInvalidWebSocketUse(
"Invalid usage of web socket endpoint without WebSocketBuilder2. " +
"Use the toWebSocketRoutes/toWebSocketHttp interpreter methods, " +
"and add the result using BlazeServerBuilder.withHttpWebSocketApp(..)."
)
pipeF.flatMap { pipe =>
webSocketBuilder match {
case Some(wsb) => wsb.withHeaders(headers).build(pipe)
case None =>
monad.error(
new Http4sInvalidWebSocketUse(
"Invalid usage of web socket endpoint without WebSocketBuilder2. " +
"Use the toWebSocketRoutes/toWebSocketHttp interpreter methods, " +
"and add the result using BlazeServerBuilder.withHttpWebSocketApp(..)."
)
}
)
}
}
case Some(Right((entity, contentLength))) =>
Expand Down

0 comments on commit 5aa112d

Please sign in to comment.