PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/rack/mime.rb

https://github.com/johnl/deb-ruby-rack
Ruby | 213 lines | 181 code | 3 blank | 29 comment | 0 complexity | 5dbf19441bacfb7e240f4160af6d7f3d MD5 | raw file
  1. module Rack
  2. module Mime
  3. # Returns String with mime type if found, otherwise use +fallback+.
  4. # +ext+ should be filename extension in the '.ext' format that
  5. # File.extname(file) returns.
  6. # +fallback+ may be any object
  7. #
  8. # Also see the documentation for MIME_TYPES
  9. #
  10. # Usage:
  11. # Rack::Mime.mime_type('.foo')
  12. #
  13. # This is a shortcut for:
  14. # Rack::Mime::MIME_TYPES.fetch('.foo', 'application/octet-stream')
  15. def mime_type(ext, fallback='application/octet-stream')
  16. MIME_TYPES.fetch(ext.to_s.downcase, fallback)
  17. end
  18. module_function :mime_type
  19. # List of most common mime-types, selected various sources
  20. # according to their usefulness in a webserving scope for Ruby
  21. # users.
  22. #
  23. # To amend this list with your local mime.types list you can use:
  24. #
  25. # require 'webrick/httputils'
  26. # list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types')
  27. # Rack::Mime::MIME_TYPES.merge!(list)
  28. #
  29. # N.B. On Ubuntu the mime.types file does not include the leading period, so
  30. # users may need to modify the data before merging into the hash.
  31. #
  32. # To add the list mongrel provides, use:
  33. #
  34. # require 'mongrel/handlers'
  35. # Rack::Mime::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES)
  36. MIME_TYPES = {
  37. ".3gp" => "video/3gpp",
  38. ".a" => "application/octet-stream",
  39. ".ai" => "application/postscript",
  40. ".aif" => "audio/x-aiff",
  41. ".aiff" => "audio/x-aiff",
  42. ".asc" => "application/pgp-signature",
  43. ".asf" => "video/x-ms-asf",
  44. ".asm" => "text/x-asm",
  45. ".asx" => "video/x-ms-asf",
  46. ".atom" => "application/atom+xml",
  47. ".au" => "audio/basic",
  48. ".avi" => "video/x-msvideo",
  49. ".bat" => "application/x-msdownload",
  50. ".bin" => "application/octet-stream",
  51. ".bmp" => "image/bmp",
  52. ".bz2" => "application/x-bzip2",
  53. ".c" => "text/x-c",
  54. ".cab" => "application/vnd.ms-cab-compressed",
  55. ".cc" => "text/x-c",
  56. ".chm" => "application/vnd.ms-htmlhelp",
  57. ".class" => "application/octet-stream",
  58. ".com" => "application/x-msdownload",
  59. ".conf" => "text/plain",
  60. ".cpp" => "text/x-c",
  61. ".crt" => "application/x-x509-ca-cert",
  62. ".css" => "text/css",
  63. ".csv" => "text/csv",
  64. ".cxx" => "text/x-c",
  65. ".deb" => "application/x-debian-package",
  66. ".der" => "application/x-x509-ca-cert",
  67. ".diff" => "text/x-diff",
  68. ".djv" => "image/vnd.djvu",
  69. ".djvu" => "image/vnd.djvu",
  70. ".dll" => "application/x-msdownload",
  71. ".dmg" => "application/octet-stream",
  72. ".doc" => "application/msword",
  73. ".dot" => "application/msword",
  74. ".dtd" => "application/xml-dtd",
  75. ".dvi" => "application/x-dvi",
  76. ".ear" => "application/java-archive",
  77. ".eml" => "message/rfc822",
  78. ".eps" => "application/postscript",
  79. ".exe" => "application/x-msdownload",
  80. ".f" => "text/x-fortran",
  81. ".f77" => "text/x-fortran",
  82. ".f90" => "text/x-fortran",
  83. ".flv" => "video/x-flv",
  84. ".for" => "text/x-fortran",
  85. ".gem" => "application/octet-stream",
  86. ".gemspec" => "text/x-script.ruby",
  87. ".gif" => "image/gif",
  88. ".gz" => "application/x-gzip",
  89. ".h" => "text/x-c",
  90. ".htc" => "text/x-component",
  91. ".hh" => "text/x-c",
  92. ".htm" => "text/html",
  93. ".html" => "text/html",
  94. ".ico" => "image/vnd.microsoft.icon",
  95. ".ics" => "text/calendar",
  96. ".ifb" => "text/calendar",
  97. ".iso" => "application/octet-stream",
  98. ".jar" => "application/java-archive",
  99. ".java" => "text/x-java-source",
  100. ".jnlp" => "application/x-java-jnlp-file",
  101. ".jpeg" => "image/jpeg",
  102. ".jpg" => "image/jpeg",
  103. ".js" => "application/javascript",
  104. ".json" => "application/json",
  105. ".log" => "text/plain",
  106. ".m3u" => "audio/x-mpegurl",
  107. ".m4v" => "video/mp4",
  108. ".man" => "text/troff",
  109. ".manifest"=> "text/cache-manifest",
  110. ".mathml" => "application/mathml+xml",
  111. ".mbox" => "application/mbox",
  112. ".mdoc" => "text/troff",
  113. ".me" => "text/troff",
  114. ".mid" => "audio/midi",
  115. ".midi" => "audio/midi",
  116. ".mime" => "message/rfc822",
  117. ".mml" => "application/mathml+xml",
  118. ".mng" => "video/x-mng",
  119. ".mov" => "video/quicktime",
  120. ".mp3" => "audio/mpeg",
  121. ".mp4" => "video/mp4",
  122. ".mp4v" => "video/mp4",
  123. ".mpeg" => "video/mpeg",
  124. ".mpg" => "video/mpeg",
  125. ".ms" => "text/troff",
  126. ".msi" => "application/x-msdownload",
  127. ".odp" => "application/vnd.oasis.opendocument.presentation",
  128. ".ods" => "application/vnd.oasis.opendocument.spreadsheet",
  129. ".odt" => "application/vnd.oasis.opendocument.text",
  130. ".ogg" => "application/ogg",
  131. ".ogv" => "video/ogg",
  132. ".p" => "text/x-pascal",
  133. ".pas" => "text/x-pascal",
  134. ".pbm" => "image/x-portable-bitmap",
  135. ".pdf" => "application/pdf",
  136. ".pem" => "application/x-x509-ca-cert",
  137. ".pgm" => "image/x-portable-graymap",
  138. ".pgp" => "application/pgp-encrypted",
  139. ".pkg" => "application/octet-stream",
  140. ".pl" => "text/x-script.perl",
  141. ".pm" => "text/x-script.perl-module",
  142. ".png" => "image/png",
  143. ".pnm" => "image/x-portable-anymap",
  144. ".ppm" => "image/x-portable-pixmap",
  145. ".pps" => "application/vnd.ms-powerpoint",
  146. ".ppt" => "application/vnd.ms-powerpoint",
  147. ".ps" => "application/postscript",
  148. ".psd" => "image/vnd.adobe.photoshop",
  149. ".py" => "text/x-script.python",
  150. ".qt" => "video/quicktime",
  151. ".ra" => "audio/x-pn-realaudio",
  152. ".rake" => "text/x-script.ruby",
  153. ".ram" => "audio/x-pn-realaudio",
  154. ".rar" => "application/x-rar-compressed",
  155. ".rb" => "text/x-script.ruby",
  156. ".rdf" => "application/rdf+xml",
  157. ".roff" => "text/troff",
  158. ".rpm" => "application/x-redhat-package-manager",
  159. ".rss" => "application/rss+xml",
  160. ".rtf" => "application/rtf",
  161. ".ru" => "text/x-script.ruby",
  162. ".s" => "text/x-asm",
  163. ".sgm" => "text/sgml",
  164. ".sgml" => "text/sgml",
  165. ".sh" => "application/x-sh",
  166. ".sig" => "application/pgp-signature",
  167. ".snd" => "audio/basic",
  168. ".so" => "application/octet-stream",
  169. ".svg" => "image/svg+xml",
  170. ".svgz" => "image/svg+xml",
  171. ".swf" => "application/x-shockwave-flash",
  172. ".t" => "text/troff",
  173. ".tar" => "application/x-tar",
  174. ".tbz" => "application/x-bzip-compressed-tar",
  175. ".tcl" => "application/x-tcl",
  176. ".tex" => "application/x-tex",
  177. ".texi" => "application/x-texinfo",
  178. ".texinfo" => "application/x-texinfo",
  179. ".text" => "text/plain",
  180. ".tif" => "image/tiff",
  181. ".tiff" => "image/tiff",
  182. ".torrent" => "application/x-bittorrent",
  183. ".tr" => "text/troff",
  184. ".ttf" => "application/octet-stream",
  185. ".txt" => "text/plain",
  186. ".vcf" => "text/x-vcard",
  187. ".vcs" => "text/x-vcalendar",
  188. ".vrml" => "model/vrml",
  189. ".war" => "application/java-archive",
  190. ".wav" => "audio/x-wav",
  191. ".webm" => "video/webm",
  192. ".wma" => "audio/x-ms-wma",
  193. ".wmv" => "video/x-ms-wmv",
  194. ".wmx" => "video/x-ms-wmx",
  195. ".woff" => "application/octet-stream",
  196. ".wrl" => "model/vrml",
  197. ".wsdl" => "application/wsdl+xml",
  198. ".xbm" => "image/x-xbitmap",
  199. ".xhtml" => "application/xhtml+xml",
  200. ".xls" => "application/vnd.ms-excel",
  201. ".xml" => "application/xml",
  202. ".xpm" => "image/x-xpixmap",
  203. ".xsl" => "application/xml",
  204. ".xslt" => "application/xslt+xml",
  205. ".yaml" => "text/yaml",
  206. ".yml" => "text/yaml",
  207. ".zip" => "application/zip",
  208. }
  209. end
  210. end