Skip to content

Commit

Permalink
Update Handler.scala
Browse files Browse the repository at this point in the history
Fix #2372
  • Loading branch information
ioleo authored Sep 22, 2023
1 parent 8780eb9 commit 5159fbc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions zio-http/src/main/scala/zio/http/Handler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,16 @@ sealed trait Handler[-R, +Err, -In, +Out] { self =>

object Handler {

def asStreamBounded(request: Request, limit: Int): Handler[Any, Throwable, Any, Chunk[Byte]] =
Handler.fromZIO(
request.body.asStream
.chunks
.runFoldZIO(Chunk.empty[Byte])((acc, bytes) =>
ZIO.succeed(acc ++ bytes)
.filterOrFail(_.sizeIs < limit)(new Exception("Too large input"))
)
)

/**
* Attempts to create a Handler that succeeds with the provided value,
* capturing all exceptions on it's way.
Expand Down

0 comments on commit 5159fbc

Please sign in to comment.