Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
修正使用非 GET,HEAD 请求时碰到 302 时,请求方法保持不变的 Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Medicean committed May 12, 2016
1 parent b9d6906 commit e9a0e6a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hackhttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"""

__title__ = 'hackhttp'
__version__ = '1.0.0'
__version__ = '1.0.2'
__build__ = 0x020700
__author__ = 'BugScanTeam'
__author_email__ = 'admin@bugscan.net'
Expand Down
1 change: 1 addition & 0 deletions hackhttp/hackhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def _http(
rep.version * 0.1, rep.status,
rep.reason) + '\r\n' + str(retheader) + '\r\n' + (body[:4096])
if location and url != redirect and locationcount < 5:
method = 'HEAD' if method == 'HEAD' else 'GET'
a, b, c, d, e = self._http(
redirect, method=method, proxy=proxy,
cookcookie=cookcookie, location=location,
Expand Down

1 comment on commit e9a0e6a

@Medicean
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要注意,RFC1945 中规定如下:

302 Moved Temporarily

请求到的资源在一个不同的URL处临时保存。因为重定向有时会被更改,客户端
应继续用请求URI来发出以后的请求。

新的URL必须由回应中的位置域指定。除非是HEAD请求,否则回应的实体主体
(Entity-Body)必须包括对新URL超链接的简要描述。

如果用POST方法发出请求,而接收到302回应状态码。在这种情况下,除非用户
确认,否则用户代理不必自动重定向请求,因为这将导致改变已发出请求的环境。

注意:当在接收到302状态码后而自动重定向POST请求时,一些现存的用户代理
会错误地将其改为GET请求。

此处 hackhttp 与 RFC1945 有出入,hackhttp 如果指定了 location=True ,则碰到非 GET, HEAD 请求时,会以 GET 请求继续访问 Response 中 Location 指定的 URI。

Please sign in to comment.