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?

More than 3 years have passed since last update.

[Webを支える技術] HTTPヘッダの概要

Last updated at Posted at 2021-05-20

HTTPヘッダ

HTTPヘッダとは次のようなものです。RequestとResponseで使うパラメータが若干違います。

Request
GET /home.html HTTP/1.1
Host: developer.mozilla.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://developer.mozilla.org/testpage.html
Connection: keep-alive
Upgrade-Insecure-Requests: 1
If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT
If-None-Match: "c561c68d0ba92bbeb8b0fff2a9199f722e3a621a"
Cache-Control: max-age=0

例引用

Response
200 OK
Access-Control-Allow-Origin: *
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Mon, 18 Jul 2016 16:06:00 GMT
Etag: "c561c68d0ba92bbeb8b0f612a9199f722e3a621a"
Keep-Alive: timeout=5, max=997
Last-Modified: Mon, 18 Jul 2016 02:36:04 GMT
Server: Apache
Set-Cookie: mykey=myvalue; expires=Mon, 17-Jul-2017 16:06:00 GMT; Max-Age=31449600; Path=/; secure
Transfer-Encoding: chunked
Vary: Cookie, Accept-Encoding
X-Backend-Server: developer2.webapp.scl3.mozilla.com
X-Cache-Info: not cacheable; meta data too large
X-kuma-revision: 1085259
x-frame-options: DENY

例引用

よく使われるHTTPヘッダ

Date

日時のデータを持つヘッダです。HTTPでは電子メールのフォーマットを使用しています。

Date
Date: Mon, 17 May 2020 11:06:49 GMT

Responseで使われるDate

  • If-Modified-Since
  • If-Unmodified-Since

どちらもリクエストを条件付にします。
If-Modified-SinceはGETメソッドでリソースの更新日時を指定する場合に使います。
If-Unmodified-SinceはPUTやDELETEメソッド等でリソースの更新日時を指定する場合に使います。

Request

  • Expires
  • Last-Modified
  • Retry-After

Expriesはキャッシュできる時間を指定します。
Last-Modifiedはリソースを最後に更新した時間が入ります。
Retry-Afterはもう一度Requestを送信できる日時が入ります。

MIMEメディアタイプ

Content-Type

ボディに入っているコンテンツが何なのかを指定します。

  • application
  • audio
  • example
  • font
  • model
  • text
  • video

Content-Type: text/html;の右のように、書き方はタイプ/サブタイプとなります。
今回の例で言えば、textが入っていて、その中身はhtmlだよというのを示しています。

charset

コンテンツの文字フォーマットが何でエンコードしているのかを指定します。

charset
Content-Type: text/html; charset=utf-8

このパラメータは省略可能なのですが、もしContent-Typeがtextを指定していて、日本語を扱う場合は注意が必要です。HTTPでは、Content-TypeがtextのものはISO 8859-1と定義されており、英語以外で書かれた文書はcharsetを省くと文字化けを起こしてしまいます。

言語タグ

コンテンツのエンコードを示すものはcharsetでしたが、コンテンツのリソース表現の自然言語を示すものもあります。

Content-Language
Content-Language: ja-JP

コンテンツネゴシエーション

クライアントが処理できるContent-Typeで指定できるコンテンツを、サーバー側へ伝えるものです。

Accept

Accept
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8

Acceptはクライアントが処理できるコンテンツを羅列できます

送られたサーバーは、Acceptから一つを選択し、Responseを返します。

Content-Length

Bodyの長さを指定します。
10進数のバイトで表記できます。

Content-Length: 256

Transfer-Encoding

bodyを分割して送ることができます。

Transfer-Encoding: chunked
Transfer-Encoding: compress
Transfer-Encoding: deflate
Transfer-Encoding: gzip
Transfer-Encoding: identity

例引用

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?