简体   繁体   中英

Content-length when redirecting in express

It seems that every time I try to redirect a user, express is wrongly adding a Content-Length to the header:

app.use(function(req, res, next) {
  res.redirect('/');
});

Output:

curl -I http://127.0.0.1:8080/action
HTTP/1.1 302 Moved Temporarily
X-Powered-By: Express
Location: /
Vary: Accept
Content-Type: text/plain; charset=UTF-8
Content-Length: 35
Date: Thu, 24 Jul 2014 16:38:27 GMT
Connection: keep-alive

Since the response doesn't have a body, I'm wondering why is this happening?

There is nothing in the spec that prevents responses with that status code from having a body. Most likely the content is some kind of human-readable message about the redirect.

So the Content-Length is the length of the content you would ordinarily see if you were using a method other than HEAD.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM