Skip to content

Commit f18b4ea

Browse files
committed
added e2e tests for status 413, 504
1 parent 31aef29 commit f18b4ea

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

cgi-bin/timeout.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2024-2025 lfortin
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining
4+
// a copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to
8+
// permit persons to whom the Software is furnished to do so, subject to
9+
// the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
process.stdout.write("Content-Type: text/plain\n");
23+
process.stdout.write("\n");
24+
25+
// Simulate a long-running process
26+
setTimeout(() => {
27+
process.stdout.write("Hello, World!");
28+
}, 5000);

cypress/e2e/spec.cy.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ describe("HTTP response status", () => {
4040
expect(response.body).to.equal("Not Found");
4141
});
4242
});
43+
it("should get status 413 Entity Too Large", () => {
44+
const bigPayload = "A".repeat(3 * 1024 * 1024); // 3 MB payload
45+
46+
cy.request({
47+
url: "/cgi-bin/env.js",
48+
method: "POST",
49+
body: bigPayload,
50+
failOnStatusCode: false,
51+
}).then((response) => {
52+
expect(response.status).to.equal(413);
53+
});
54+
});
4355
it("should get status 500 Internal Server Error", () => {
4456
cy.request({
4557
url: "/cgi-bin/error.js",
@@ -56,6 +68,14 @@ describe("HTTP response status", () => {
5668
expect(response.status).to.equal(200);
5769
});
5870
});
71+
it("should get status 504 Gateway Timeout", () => {
72+
cy.request({
73+
url: "/cgi-bin/timeout.js",
74+
failOnStatusCode: false,
75+
}).then((response) => {
76+
expect(response.status).to.equal(504);
77+
});
78+
});
5979
});
6080
describe("HTTP response body", () => {
6181
it("should have html payload", () => {

server/http.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ const callback = createHandler({
3838
indexExtension: "cgi",
3939
debugOutput: true,
4040
logRequests: true,
41-
maxBuffer: 4 * 1024 ** 2,
41+
maxBuffer: 1024 ** 2, // 1MB
4242
requestChunkSize: 4 * 1024,
4343
responseChunkSize: 4 * 1024,
44-
requestTimeout: 30000,
44+
requestTimeout: 3000, // 3s
4545
env: (env, req) => {
4646
return {
4747
REMOTE_AGENT: req.headers["user-agent"],

server/https.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ const callback = createHandler({
3939
indexExtension: "cgi",
4040
debugOutput: true,
4141
logRequests: true,
42-
maxBuffer: 4 * 1024 ** 2,
42+
maxBuffer: 1024 ** 2, // 1MB
4343
requestChunkSize: 4 * 1024,
4444
responseChunkSize: 4 * 1024,
45-
requestTimeout: 30000,
45+
requestTimeout: 3000, // 3s
4646
env: (env, req) => {
4747
return {
4848
REMOTE_AGENT: req.headers["user-agent"],

0 commit comments

Comments
 (0)