Skip to content

Commit 4bc3f34

Browse files
committed
Move max body size validation to after the gzip->base64 conversion
1 parent 2a2973e commit 4bc3f34

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/OriginRequestInterface.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,26 @@ module.exports = class OriginRequestInterface {
5555
this.headers[key] = val;
5656
},
5757
end: body => {
58-
if (body && body.length >= 255000) {
59-
console.log("bailing out because size is over 256kb");
60-
return next();
61-
}
62-
6358
const res = {
6459
status: this.status,
6560
statusDescription: "OK",
6661
headers: this.headers,
6762
body: body
6863
};
6964

70-
if (this.originalHeaders["content-encoding"] && this.originalHeaders["content-encoding"].match(/gzip/)) {
65+
if (
66+
this.originalHeaders["content-encoding"] &&
67+
this.originalHeaders["content-encoding"].match(/gzip/)
68+
) {
7169
res.body = res.body.toString("base64");
7270
res.bodyEncoding = "base64";
7371
}
7472

73+
if (body && body.length >= 255000) {
74+
console.log("bailing out because size is over 256kb");
75+
return next();
76+
}
77+
7578
return this.callback(null, res);
7679
},
7780
writeHead: (_status, _headers) => {

0 commit comments

Comments
 (0)