0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

リクエスト/レスポンスヘッダーの自動設定比較表(Spring MVC, Spring WebFlux, Tomcat, Reactor Netty, Apache HttpClient)

Posted at

リクエストヘッダーの自動設定比較表

ヘッダー名 Spring MVC Spring WebFlux Tomcat Reactor Netty Apache HttpClient
Content-Type ✅ 自動(@RequestBodyなど) ✅ 自動(Mono/Fluxの型に応じて) ✅ リクエストから解析 ✅ リクエストから解析 ✅ 自動(Entityから推測)
Content-Length ✅ 自動設定(明示されていない場合) ✅ 自動(Fluxなどでは未設定) ✅ 自動(ボディあり時) ✅ 自動(ボディサイズで) ✅ 自動(Entityサイズに応じて)
Transfer-Encoding ✅ 自動(Content-Lengthが無いとき) ✅ 自動(chunkedが多い) ✅ 自動(HTTP/1.1で必要時) ✅ 自動(chunkedに) ✅ 自動(ストリーム送信時)
Authorization ✅ Spring Securityで処理 ✅ 同左 ❌ 自動付与しない ❌ 同左 ❌ 明示的に付与が必要
User-Agent ❌(クライアントに依存) ✅ クライアント送信値 ✅ 同左 ✅ 自動(デフォルト値あり)
Accept ✅ 自動(producesによる) ✅ 自動(producesによる) ✅ クライアント送信値 ✅ 同左 ✅ 自動(JSONなどに応じて)
Cookie ✅ 自動で解釈 ✅ 同左 ✅ パースのみ ✅ パースのみ ✅ 自動(HttpContext使用時)
X-Forwarded-For ✅(Proxy通過時) ✅ 同左 ✅ Proxyから付与 ✅ 同左 ❌ 明示的に必要
Host ✅ 自動設定 ✅ 同左 ✅ クライアント送信値 ✅ 同左 ✅ 自動(URIから)

レスポンスヘッダーの自動設定比較表

ヘッダー名 Spring MVC Spring WebFlux Tomcat Reactor Netty Apache HttpClient
Content-Type ✅ 自動(produces属性/ResponseEntity) ✅ 自動(Monoの型) ✅ 自動設定される ✅ 自動設定される ✅ サーバからの値をそのまま取得
Content-Length ✅ 自動(静的コンテンツなど) ❌(通常未設定) ✅ 自動(静的リソースなど) ❌(chunkedに依存) ✅ サーバからの値をそのまま取得
Transfer-Encoding ✅ 自動(サイズ不明時) ✅ chunkedが基本 ✅ chunkedを自動付加 ✅ chunkedを自動付加 ✅ chunked など受信値そのまま
Set-Cookie ✅ 自動(HttpServletResponseに追加) ✅ 自動(ResponseCookie) ✅ 自動でヘッダー出力 ✅ 同左 ✅ クッキーの受信可能
Cache-Control ✅ 明示しない限りは未設定 ✅ 同左 ❌ デフォルトではなし ❌ 同左 ✅ 受信ヘッダーとして取得可能
Connection ✅ HTTP/1.1でkeep-alive ✅ 同左 ✅ keep-alive自動設定 ✅ 同左 ✅ 受信ヘッダーに含まれる
Date ✅ 自動(HttpServlet仕様) ✅ 自動 ✅ 自動付加 ✅ 自動付加 ✅ サーバからの受信内容
Server ❌ デフォルトなし ✅ Apache Tomcat/X.X.X ✅ ReactorNetty/X.X.X ✅ サーバ側が送信した値

補足ポイント

Spring MVC / WebFlux の自動設定は、アノテーションやレスポンスボディの内容に基づいて行われます。

Tomcat / Netty はそれぞれのサーバとしての役割で HTTP 仕様に準拠した自動設定を行います。

Apache HttpClient はクライアント側ライブラリであり、送信時の一部ヘッダーは自動設定されますが、Authorization などは明示的に設定する必要があります。

Transfer-Encoding や Content-Length は、ボディの存在・サイズにより自動的に判断されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?