mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(api): stop bounding request body receipt at the header timeout (#2245)
This commit is contained in:
1 parent
b4a2af75d0
commit
4b9964bc89
3 files changed
+50
-2
No files matched your search
@@ -42,7 +42,7 @@ describe('Server limits', () => {
|
||||
const listening = await listen({port: 0});
|
||||
server = listening.server;
|
||||
const httpServer = server as Server;
|
||||
expect(httpServer.requestTimeout).toBe(30_000);
|
||||
expect(httpServer.requestTimeout).toBe(120_000);
|
||||
expect(httpServer.keepAliveTimeout).toBe(125_000);
|
||||
expect(httpServer.maxRequestsPerSocket).toBe(1_000);
|
||||
expect(httpServer.headersTimeout).toBeLessThanOrEqual(httpServer.requestTimeout);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {Hono} from 'hono';
|
||||
import {afterEach, describe, expect, it} from 'vitest';
|
||||
import {createServer} from '../Server';
|
||||
|
||||
const servers: Array<{close: (cb: () => void) => void}> = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(servers.splice(0).map((s) => new Promise<void>((r) => s.close(() => r()))));
|
||||
});
|
||||
|
||||
function listen(options: Parameters<typeof createServer>[1]) {
|
||||
const app = new Hono();
|
||||
app.post('/echo', async (ctx) => ctx.text(String((await ctx.req.text()).length)));
|
||||
const server = createServer(app, options) as never as {
|
||||
close: (cb: () => void) => void;
|
||||
address: () => {port: number};
|
||||
headersTimeout: number;
|
||||
requestTimeout: number;
|
||||
};
|
||||
servers.push(server);
|
||||
return server;
|
||||
}
|
||||
|
||||
describe('createServer timeouts', () => {
|
||||
it('separates the header timeout from the total request timeout', () => {
|
||||
const server = listen({port: 0});
|
||||
expect(server.headersTimeout).toBe(30_000);
|
||||
expect(server.requestTimeout).toBe(120_000);
|
||||
});
|
||||
|
||||
it('lets both be overridden', () => {
|
||||
const server = listen({port: 0, headersTimeoutMs: 1_000, requestTimeoutMs: 2_000});
|
||||
expect(server.headersTimeout).toBe(1_000);
|
||||
expect(server.requestTimeout).toBe(2_000);
|
||||
});
|
||||
|
||||
it('never lets the header timeout exceed the request timeout', () => {
|
||||
const server = listen({port: 0, requestTimeoutMs: 5_000});
|
||||
expect(server.requestTimeout).toBe(5_000);
|
||||
expect(server.headersTimeout).toBeLessThanOrEqual(server.requestTimeout);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user