Skip to content

Commit

Permalink
Improve Http4sWebSockets.pipeToBody.
Browse files Browse the repository at this point in the history
Kamil Kloch committed Nov 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c885d85 commit 3859797
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -26,15 +26,12 @@ private[http4s] object Http4sWebSockets {
case Some((interval, frame)) => Stream.awakeEvery[F](interval).map(_ => frame)
case None => Stream.empty
}
val decodeClose = optionallyDecodeClose(autoPongs, o.decodeCloseRequests)

(autoPongs
.takeWhile {
case _: WebSocketFrame.Close if !o.decodeCloseRequests => false
case _ => true
}
(decodeClose
.map { f =>
o.requests.decode(f) match {
case x: DecodeResult.Value[REQ] => x.v
case x: DecodeResult.Value[REQ] => x.v
case failure: DecodeResult.Failure => throw new WebSocketFrameDecodeFailure(f, failure)
}
}
@@ -105,4 +102,12 @@ private[http4s] object Http4sWebSockets {
}
} else s
}

private def optionallyDecodeClose[F[_]](s: Stream[F, WebSocketFrame], doDecodeClose: Boolean): Stream[F, WebSocketFrame] =
if (!doDecodeClose) {
s.takeWhile {
case _: WebSocketFrame.Close => false
case _ => true
}
} else s
}

0 comments on commit 3859797

Please sign in to comment.