MagicStack / MagicStack/httptools
Response parser requires support for HEAD responses without body
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 1.3k
- 派生
- 107
- PR 合并指标
- 30 天内没有已合并 PR
描述
According to the specification of HTTP/1.1 ...
Responses to the HEAD request method never include a message body because the associated response header fields (e.g., Transfer-Encoding, Content-Length, etc.), if present, indicate only what their values would have been if the request method had been GET.
Source: RFC 7230 (Section 3.3)
... responses to HEAD requests do not have a body. Even if e.g. the Content-Length header is present.
However, the response parser cannot know based on the data it receives whether the corresponding request was using the HEAD or another method and whether to expect a body or to just ignore any header flags about the content.
Suggestion:
Add an additional boolean flag to HttpResponseParser.feed_data(self, data: bytes) to tell the parser that it should not expect a body (or even throw a parser exception if there is one present).
Because HTTP/1.1 also allows pipelining, this additional parameter should also rather be a list of "body presence" flags. Here's why:
If you send multiple requests to a server without waiting for the responses (= pipelining), you are going to receive back a bunch of responses together. Without them being parsed yet, one cannot identify the message boundaries and therefore they cannot be fed to the parser one by one. So the parser has to support that the whole stack of responses is fed to it and it needs a list of the "expected body presence".
Example:
If the pipelined requests were something like {HEAD, GET, HEAD, GET}, the "body presence" flags need to alternate as well.
For convenience, it may be good to have a parameter that can be set using both types, a single flag and a list of flags.
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 HttpResponseParser.feed_data(self, data: bytes) 开始,跟踪 pipelined responses 的响应边界和 body 预期是如何处理的。当 HEAD responses 可以在没有 body 的情况下进行解析(包括 Content-Length headers),同时 pipelined HEAD 和 GET responses 仍能正确分隔时,工作即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100