How to Limit Request Body Size in `@effect/platform` `HttpEndpoint`

Hey there! I'm trying to use HttpIncomingMessage.withMaxBodySize to limit the request body size in a
@effect/platform
HttpEndpoint. The type suggests that I could use it like this:

const ExampleApi = HttpApiBuilder.group(
  api,
  'example',
  (handlers) =>
    handlers.handle('exampleEndpoint', (req) =>
      exampleHandler(req.payload).pipe(
        HttpServerRequest.withMaxBodySize(Option.some(KiB(16))),
      ),
    ),
)


However, this doesn't seem to do anything -- even if I set this to an artificially low value, the handler effect is still executed.

From a brief look at the implementation, I can see that this sets a MaxBodySize service, so I assume this needs to be added at a lower level, ie. before the request is parsed.

My question is, where can I add this with the minimum of fuss? Do I need to define a middleware to do this?

(From an API convenience perspective, I was initially hoping that I could just define a max body size on the HttpApiEndpoint constructor, as I would probably want to add a max body size to most endpoints.)
Was this page helpful?