Skip to content

Commit

Permalink
Merge pull request #2965 from pnaik1/proxyService-8080
Browse files Browse the repository at this point in the history
make proxy service have upload byte limit
  • Loading branch information
openshift-merge-bot[bot] authored Jul 2, 2024
2 parents 5274af0 + 292916d commit cdf0d85
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion backend/src/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ 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 maxLimitInMiB = (limit / 1024 / 1024).toFixed();
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 ${maxLimitInMiB} MiB`,
413,
),
);
return;
}
const kc = fastify.kube.config;
const cluster = kc.getCurrentCluster();

Expand Down

0 comments on commit cdf0d85

Please sign in to comment.