Javascript 最多允许多少次HTTP Redirect?

阅读(3207)

HTTP Redirect(如HTTP 301,HTTP 302)不允许无限循环重定向,否则会出现错误提示,如Chrome:

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

这在HTTP 1.1规范中有明确要求:

A client SHOULD detect infinite redirection loops, since such loops generate network traffic for each redirection.
via:http://www.ietf.org/rfc/rfc2616.txt

HTTP 1.0中,最多允许5次连续的HTTP Redirect。

Note: previous versions of this specification recommended a
maximum of five redirections. Content developers should be aware
that there might be clients that implement such a fixed
limitation.
via:http://www.ietf.org/rfc/rfc2616.txt

HTTP 1.1未有明确的次数限制,现实中的情况是:

  • Chrome 和 Firefox最多允许20次HTTP Redirect。

Maximum number of redirects to follow per request. Default: 20.
via:http://kb.mozillazine.org/Network.http.redirection-limit

综合结论:最多5次HTTP Redirect是安全的。

Tags: