よく使う HTTP ヘッダー

HTTP ヘッダーは、すべてのリクエストとレスポンスの先頭に送られるキーと値のペアです。コンテンツタイプやキャッシュルール、認証といったメタデータを運びます。Web トラフィックの構築やデバッグで頻出するヘッダーをこの表で確認しましょう。

更新日:

ヘッダー方向用途
HostrequestIdentifies the server's host and port (from the URL).
User-AgentrequestReports the client software (browser, OS, bot) making the request.
AcceptrequestLists the response media types (MIME) the client can handle.
AuthorizationrequestCarries credentials (token, Basic auth) to authenticate the client.
Content-Typerequest/responseStates the media type of the request or response body.
Content-Lengthrequest/responseGives the size in bytes of the request or response body.
CookierequestSends stored key/value pairs from a previous response back to the server.
Set-CookieresponseServer instructs the client to store a cookie for later requests.
Cache-Controlrequest/responseDirects caching behaviour: no-cache, max-age, private, etc.
ETagresponseOpaque identifier for a resource version, used for revalidation.
If-None-MatchrequestSends an ETag; server returns 304 if the resource is unchanged.
LocationresponsePoints the client to a new URL for redirects (3xx) or created resources.
Access-Control-Allow-OriginresponsePermits a browser to share a response across origins (CORS).
X-Forwarded-ForrequestRecords the client IP as seen through a proxy or load balancer.
RefererrequestIndicates the URL of the page that linked to the requested resource.

注記

よくある質問

リクエストヘッダーとレスポンスヘッダーの違いは?
リクエストヘッダーはクライアント(ブラウザーやアプリ)からサーバーへ送り、レスポンスヘッダーはサーバーが答えとともに返します。Content-Type のように両方に現れるものもあります。
HTTP ヘッダー名は大文字小文字を区別しますか?
いいえ。HTTP 仕様ではヘッダー名は大文字小文字を区別しません。Content-Type と content-type は同じ意味です。Title-Case は単なる慣習です。
Host ヘッダーは何をしますか?
Host はリクエストの対象となるドメインをサーバーに伝えます。HTTP/1.1 では必須で、1 台のサーバーで複数のサイトを名前で見分けるために使われます。
ヘッダーでキャッシュはどう働きますか?
Cache-Control はレスポンスをどれくらいキャッシュしてよいかを決め、ETag と If-None-Match でクライアントが「変わった?」と聞き、変わっていなければ軽い 304 Not Modified を受け取ります。