MagicStack / MagicStack/httptools

Response parser requires support for HEAD responses without body

オープン
#47 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

HttpResponseParser.feed_data(self, data: bytes) から開始し、pipelined responses に対するレスポンス境界と body の想定がどのように処理されているかを追跡します。Content-Length ヘッダーを含め、HEAD responses を body なしでパースでき、同時に pipelined HEAD と GET responses が引き続き正しく分離されるようになれば、作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。