MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / enforceBodyLimit

Function enforceBodyLimit

apps/api/src/middleware/body-limit.ts:30–60  ·  view source on GitHub ↗
(input: {
  method: string;
  contentLength: string | null;
  maxBytes?: number;
})

Source from the content-addressed store, hash-verified

28 * this global cap.
29 */
30export const enforceBodyLimit = (input: {
31 method: string;
32 contentLength: string | null;
33 maxBytes?: number;
34}): void => {
35 if (!BODIED_METHODS.has(input.method)) {
36 return;
37 }
38
39 const cap = input.maxBytes ?? MAX_BODY_SIZE_BYTES;
40
41 if (input.contentLength === null) {
42 throw ApiErrors.validation(
43 "Content-Length header is required for requests with a body",
44 "body"
45 );
46 }
47
48 const size = Number.parseInt(input.contentLength, 10);
49
50 if (Number.isNaN(size)) {
51 throw ApiErrors.validation(
52 "Content-Length header must be a number",
53 "body"
54 );
55 }
56
57 if (size > cap) {
58 throw ApiErrors.validation("Request body exceeds 1 MB limit", "body");
59 }
60};
61
62export const bodyLimit = new Elysia().onParse(({ request }) => {
63 enforceBodyLimit({

Callers 2

body-limit.test.tsFile · 0.90
body-limit.tsFile · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected