1
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.

MIME タイプについて確認した時のメモ

Posted at

メモです。

MIME タイプとは

以下が詳しい。

MIME タイプ (IANA メディアタイプ)

抜粋

  • メディアタイプ (別名 Multipurpose Internet Mail Extensions または MIME タイプ) は、文書、ファイル、またはバイト列の性質や形式を示す標準
  • RFC 6838 で定義され、標準化されている
  • もっとも単純な MIME タイプはタイプとサブタイプで構成されている
  • これらはどちらも文字列で、その間をスラッシュ (/) で接続し、 MIME タイプを構成する。「タイプ/サブタイプ」という形式
  • 例えば、 MIME タイプが text の場合、サブタイプは plain (プレインテキスト)、 html (HTML ソースコード)、 calendar (iCalendar/.ics) ファイルなどになる(text/plain,text/html などの表記)

ざっくり理解するには以下も図などがあって参考になった

text/html【MIMEタイプ】

検証してみる

HTTP リクエスト・レスポンスで見てみる

実際に HTTP リクエスト・レスポンスで使われている部分を見てみる。

$curl -v https://www.google.co.jp
・・・(一部略)

> Host: www.google.co.jp
> User-Agent: curl/7.61.1
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
< HTTP/2 200
< date: Sat, 06 Feb 2021 20:59:28 GMT
< expires: -1
< cache-control: private, max-age=0
< content-type: text/html; charset=Shift_JIS
< p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
< server: gws
< x-xss-protection: 0
< x-frame-options: SAMEORIGIN
(以下略)

リクエストでは Accept ヘッダで使われている。

Accept

上記例では、「Accept: */*」となっており、すべての MIME タイプを意味するので「クライアントは どの MIME タイプでもレスポンスしても良い」ということを意味する。

レスポンスでは Content-type ヘッダで使われている。

Content-Type

上記例では「content-type: text/html」となっており、レスポンスが「text/html」であることを表している。

file コマンドで確認する

Linux では file コマンドで MIMEタイプが確認出来るようだった。

How can I find out a file's MIME type (Content-Type)?

こちらについても確認

# text/html の場合
$wget https://www.google.co.jp
$file --mime-type index.html
index.html: text/html

# image/png の場合 
$wget https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/500px-Google_2015_logo.svg.png
$file --mime-type 500px-Google_2015_logo.svg.png
500px-Google_2015_logo.svg.png: image/png
1
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
1
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?