Skip to content

Commit

Permalink
make proxy service have upload byte limit
Browse files Browse the repository at this point in the history
  • Loading branch information
pnaik1 committed Jun 28, 2024
1 parent fce1bf5 commit df84855
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/src/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ export const proxyService =
// preHandler must set the `upstream` param
getUpstream: (request) => getParam(request, 'upstream'),
},
preHandler: (request, _, done) => {
preHandler: (request, reply, done) => {
const limit = fastify.initialConfig.bodyLimit ?? 1024 * 1024;
const contentLength = Number(request.headers['content-length']);
if (contentLength > limit) {
reply.header('connection', 'close');
reply.send(
createCustomError(
'Payload Too Large',
'Request body is too large; the max limit is 1 MiB',
413,
),
);
return;
}
const kc = fastify.kube.config;
const cluster = kc.getCurrentCluster();

Expand Down

0 comments on commit df84855

Please sign in to comment.