官术网_书友最值得收藏!

  • Lighttpd
  • Andre Bogus
  • 380字
  • 2021-08-25 18:06:20

Mime Types

To give the client a hint of what to do with a file, the HTTP protocol defines that each file should be sent with a Mime type. A Mime type consists of a Content type and a subtype. The Content type is one of application, audio, example, image, message, model, multipart, text, and video. Subtypes can be registered with IANA by a Web form. The Internet Assigned Numbers Authority (IANA) maintains a list of mime types. Most Linux or BSD systems have a local list at /etc/mime.types. The authoritative list can be found at http://www.iana.org/assignments/media-types.

Note

All mime types

You can download a mime-types.py python script that uses the mime type module to create a mime type mapping suitable for inclusion in a Lighttpd configuration at http://packtpub.com/files/code/2103_Code.zip. Start the script with python mime-types.py and it writes a mime-types.conf file in the current directory.

If you do not have a python interpreter, get one from http://www.python.org.

For a single web project, a fairly small map of mime types will usually suffice:

mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".gif" => "image/gif",
".png" => "image/png",
".zip" => "application/zip",
".tar.gz" => "application/x-tgz",
".gz" => "application/x-gzip")

Note the last two entries; the order is of the essence here. Had we swapped them, any .tar.gz file would match .gz and would thus be served as application/x-gzip.

Note

Default mime type

Using an empty extension, you can define a default mime type that will be used if no matching extension can be found, like we did in our first lighttpd.conf example.

The standard mime type for an HTML page is "text/html", but this changes if you use XHTML, which can be sent as "text/html", "text/xml" or "application/xml", the correct type being "application/xhtml+xml". Some browsers react differently on each type. Storing them with the extension " .xhtml" will make it easier to distinguish between HTML and XHTML files.

If the file system in use supports XFS-style attributes, we can set the mime type for each file with the attr program:

attr -s Content-Type -V image/jpeg foto.jpg

This Content-Type attribute can be used wherever it is present by setting

mimetype.use-xattr = "enable"

in our lighttpd.conf file, Lighttpd will fall back to the mime-type.assignment for files without Content-Type attribute.

主站蜘蛛池模板: 清丰县| 永川市| 崇礼县| 神池县| 体育| 内江市| 三亚市| 合肥市| 黔西| 古蔺县| 丰县| 合阳县| 冕宁县| 武陟县| 张家口市| 陇南市| 巢湖市| 库尔勒市| 韩城市| 遂川县| 当雄县| 农安县| 衡东县| 怀柔区| 新泰市| 吴堡县| 右玉县| 辉南县| 商城县| 沙坪坝区| 景谷| 嘉义县| 江口县| 连平县| 贵阳市| 平果县| 谷城县| 北票市| 兰溪市| 辽阳县| 称多县|