Repository navigation
fix(http): 本文の無い 204 / 304 に Content-Type を付けない - #141
Merged
Merged
Conversation
本文の無い 204 / 304 に PHP の既定の
`Content-type: text/html; charset=UTF-8` が付いていたのを止める。
`header_remove('Content-Type')` だけでは default_mimetype は止まらないため、
空の `Content-Type:` を一度置いてから外す(BodilessHeaders)。
- Response::send(): 204 / 304 で、ハンドラが Content-Type を明示していなければ外す
(route.php の自動 OPTIONS、ページの自動 OPTIONS、noContent() を含む)
- CachePolicy::sendNotModified(): HTTP キャッシュの 304
- Cors のプリフライト 204
Closes #135
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #135
Summary
本文の無い 204 / 304 に、PHP の既定の
Content-type: text/html; charset=UTF-8が付いていたのを止めます。header_remove('Content-Type')だけではdefault_mimetypeは止まりません(php -Sで確認済み)。空のContent-Type:を一度置いてから外すと止まるので、この処理をHttp\BodilessHeaders(@internal)にまとめました。Response::send(): ステータスが 204 / 304 で、ハンドラがContent-Typeを明示していないときに外します。route.phpの自動OPTIONS、ページの自動OPTIONS、Response::noContent()がここを通ります。Content-Typeを明示した場合はそのまま送ります。CachePolicy::sendNotModified(): HTTP キャッシュの 304 はResponseを経由しないので、ここでも外します(php -Sでは元から付いていませんでしたが、SAPI によっては付くかもしれないので念のため)。Corsのプリフライト 204 もResponseを経由しないので、同じく外します。noContent()の説明に、Content-Typeを付けないことを書き足しました。テスト
tests/Http/BodilessResponseHttpServerTest.phpを追加しました。既定の Content-Type は SAPI がヘッダを送る時点で付くため、プロセス内のテストや Xdebug のヘッダ一覧では見えません。そこで、既存の*HttpServerTestと同じく本物のphp -Sに対して確かめています。DELETE→noContent()、If-None-Matchによる 304、CORS プリフライトにContent-Typeが無いことContent-Typeを明示した場合と、本文のある応答ではContent-Typeが残ること修正前は、自動 OPTIONS(route)、
noContent()、プリフライトの 3 件が落ちることを確認しています。phpunit/phpstan analyse/php-cs-fixer fix --dry-runはすべて通ります。🤖 Generated with Claude Code