( request: HttpServerRequest, stream: Stream.Stream<Uint8Array, HttpServerError>, maxBytes: number )
| 1008 | }) |
| 1009 | |
| 1010 | const limitStream = ( |
| 1011 | request: HttpServerRequest, |
| 1012 | stream: Stream.Stream<Uint8Array, HttpServerError>, |
| 1013 | maxBytes: number |
| 1014 | ): Stream.Stream<Uint8Array, HttpServerError> => |
| 1015 | Stream.suspend(() => { |
| 1016 | let bytes = 0 |
| 1017 | return Stream.mapEffect(stream, (chunk) => { |
| 1018 | bytes += chunk.byteLength |
| 1019 | return bytes > maxBytes |
| 1020 | ? Effect.fail(bodyTooLargeError(request, new BodyTooLargeError(maxBytes))) |
| 1021 | : Effect.succeed(chunk) |
| 1022 | }) |
| 1023 | }) |
| 1024 | |
| 1025 | const bodyTooLargeError = (request: HttpServerRequest, cause: BodyTooLargeError) => |
| 1026 | new HttpServerError({ reason: new RequestParseError({ request, reason: "BodyTooLarge", cause }) }) |
no test coverage detected