Skip to content

fix(http2): PATCH/DELETEなど本文付きリクエストでもcontent-lengthを付与する - #276

Merged
funa-tk merged 1 commit into
DeNA:masterfrom
toku-sa-n:fix/http2-content-length-for-body-methods
Oct 22, 2026
Merged

funa-tk merged 1 commit into
DeNA:masterfrom
toku-sa-n:fix/http2-content-length-for-body-methods

Conversation

@toku-sa-n

Copy link
Copy Markdown
Contributor

HTTP/2で本文付きのPATCHやDELETEを中継すると、上流のサーバが400 Bad Requestを返す問題を修正しました。

原因

HeadersFrame.encodeFromHttp() でcontent-lengthを付け直す(MetaData.Request に本文長を渡す)対象が、POSTとPUTだけになっていました。PATCHやDELETEはどちらの分岐にも入らず、本文長が0のまま渡されます。そのため、ヘッダでは本文長0と宣言しながら、実際には空でないDATAフレームを送る、という食い違った状態になっていました。厳格なサーバはこれを不正なリクエストとして400で拒否します。HTTP/1.1ではこの経路を通らず元のContent-Lengthがそのまま使われるので、同じリクエストでも成功します。

変更内容

  • GET/HEAD以外のすべてのメソッドで、POST/PUTと同じようにcontent-lengthを付与するようにしました。
  • 本文付きのPATCHをエンコードしたときに、content-lengthが本文長と一致することを確かめる回帰テストを HeadersFrameTest に追加しました。修正前のコードではこのテストが失敗することを確認しています。

補足

  • 本文のないDELETEなどにも content-length: 0 が付くようになります。

  • By placing an "x" in the box, I hereby understand, accept and agree to be bound by the terms and conditions of the Contribution License Agreement.

🤖 Generated with Claude Code

…g methods

HeadersFrame.encodeFromHttp() only re-added the content-length header (and
passed a non-zero contentLength to MetaData.Request) for POST and PUT. For
other body-bearing methods such as PATCH and DELETE, contentLength stayed 0,
so the reconstructed HTTP/2 request declared a zero-length body while a
non-empty DATA frame followed.

Strict upstreams reject this mismatch with 400 Bad Request, while the same
request over HTTP/1.1 succeeds because it keeps the original Content-Length.
Handle every non-GET/HEAD method the same way, and add a regression test that
encodes a PATCH with a body and checks the declared length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@toku-sa-n
toku-sa-n marked this pull request as ready for review October 22, 2026 10:42

@funa-tk funa-tk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

eclipse.orgが落ちててフォーマットのテストがチェックが通っていませんが、内容は問題ないですので、マージさせていただきます。

@funa-tk
funa-tk merged commit e1fd44f into DeNA:master Oct 22, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants