U
U
Ulyan Romanov2021-10-19 18:53:32
Node.js
Ulyan Romanov, 2021-10-19 18:53:32

How to get 408 error in browser?

There is a simple koa server. There is Chrome. The server has this code:

router.post(/\/api\/gw\/query/, async (ctx, next) => {
    await sleep(6 * 60000); // 6 минут
});


In the chrome source there is such a connection about
int64_t g_used_idle_socket_timeout_s = 300; // 5 minutes

My server has this:
server.keepAliveTimeout = 2000;
server.headersTimeout = 2000;


I can only get 504 this way
// server.setTimeout(5000);

But I'm trying to figure out how to get 408 without manually sending it from the server. If that's even possible.
And if not, when and under what conditions is 408 sent?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Ulyan Romanov, 2021-10-19
@TexxTyRe

Everything turned out to be very simple
. You need to add a timeout (better done for a specific request) in the request

router.post(/\/api\/gw\/query/, async (ctx, next) => {
    ctx.request.socket.setTimeout(4000);
    await sleep(6 * 60000); // 6 минут
});

And add a timeout handler for the server
const server = app.listen(3000);
server.on('timeout', (socket) => {
    console.log('timeout', socket)
    socket.write([
        'HTTP/1.1 408 Request Timeout',
        'Connection: close'
    ].join('\n') + '\n\n');

    socket.end();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question