H
H
Hiroshima2021-08-15 17:02:08
Node.js
Hiroshima, 2021-08-15 17:02:08

Why is it not possible to set the headers after they are sent to the client?

I'm having a problem redirecting the user to another page after a while:

return(setTimeout(function restart(){
                res.render('index')
            }, 4000));


The problem is in this piece of code (
the error sounds like this:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:561:11)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
abberati, 2021-08-16
@abberati

Why can't you fry potatoes after you've eaten them?

S
Sergey delphinpro, 2021-08-15
@delphinpro

How does the HTTP protocol work, you certainly do not know?
In short:
This is a text format.
Headers come first
Then double line
feeds Then page data

Заголовок1=значение
Заголовок2=значение
Заголовок3=значение

Тело страницы ....

If you send data, then where to stick the headers?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question