mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-06 09:25:33 +00:00
Set content-type to text/plain for all non binary files
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
# MIME types and extensions to override when the raw blob is served
|
||||
|
||||
# mime types
|
||||
application/javascript: text/plain
|
||||
application/perl: text/plain
|
||||
application/python: text/plain
|
||||
application/rdf+xml: text/plain
|
||||
application/ruby: text/plain
|
||||
application/sh: text/plain
|
||||
application/tex: text/plain
|
||||
application/xhtml+xml: text/plain
|
||||
application/xml: text/plain
|
||||
text/html: text/plain
|
||||
|
||||
# binary files
|
||||
a: application/octet-stream
|
||||
air: application/octet-stream
|
||||
blend: application/octet-stream
|
||||
crx: application/octet-stream
|
||||
deb: application/octet-stream
|
||||
gem: application/octet-stream
|
||||
graffle: application/octet-stream
|
||||
gz: application/octet-stream
|
||||
icns: application/octet-stream
|
||||
ipa: application/octet-stream
|
||||
lib: application/octet-stream
|
||||
mcz: application/octet-stream
|
||||
mov: application/octet-stream
|
||||
mp3: application/octet-stream
|
||||
nib: application/octet-stream
|
||||
o: application/octet-stream
|
||||
odp: application/octet-stream
|
||||
ods: application/octet-stream
|
||||
odt: application/octet-stream
|
||||
ogg: application/octet-stream
|
||||
ogv: application/octet-stream
|
||||
otf: application/octet-stream
|
||||
pfx: application/octet-stream
|
||||
pigx: application/octet-stream
|
||||
plgx: application/octet-stream
|
||||
pptx: application/octet-stream
|
||||
psd: application/octet-stream
|
||||
sib: application/octet-stream
|
||||
so: application/octet-stream
|
||||
spl: application/octet-stream
|
||||
sqlite3: application/octet-stream
|
||||
swc: application/octet-stream
|
||||
swf: application/octet-stream
|
||||
tar: application/octet-stream
|
||||
ucode: application/octet-stream
|
||||
xpi: application/octet-stream
|
||||
zip: application/octet-stream
|
||||
|
||||
# plaintext
|
||||
latex: text/plain
|
||||
ms: text/plain
|
||||
nc: text/plain
|
||||
nim: text/plain
|
||||
ps: text/plain
|
||||
sc: text/plain
|
||||
sh: text/plain
|
||||
src: text/plain
|
||||
tcl: text/plain
|
||||
texi: text/plain
|
||||
texinfo: text/plain
|
||||
xul: text/plain
|
||||
@@ -51,36 +51,6 @@ module Linguist
|
||||
mime_type ? mime_type.simplified : 'text/plain'
|
||||
end
|
||||
|
||||
Special = YAML.load_file(File.expand_path("../content_types.yml", __FILE__))
|
||||
|
||||
# Internal: Look up Content-Type header to serve for extension.
|
||||
#
|
||||
# This value is used when serving raw blobs.
|
||||
#
|
||||
# /github/linguist/raw/master/lib/linguist/mime.rb
|
||||
#
|
||||
# ext - The extension String. May include leading "."
|
||||
#
|
||||
# Mime.content_type_for('.html')
|
||||
# # => 'text/plain; charset=utf-8'
|
||||
#
|
||||
# Return Content-Type String otherwise falls back to
|
||||
# 'text/plain; charset=utf-8'.
|
||||
def self.content_type_for(ext)
|
||||
ext ||= ''
|
||||
|
||||
# Lookup mime type
|
||||
type = mime_for(ext)
|
||||
|
||||
# Substitute actual mime type if an override exists in content_types.yml
|
||||
type = Special[type] || Special[ext.sub(/^\./, '')] || type
|
||||
|
||||
# Append default charset to text files
|
||||
type += '; charset=utf-8' if type =~ /^text\//
|
||||
|
||||
type
|
||||
end
|
||||
|
||||
# Internal: Determine if extension or mime type is binary.
|
||||
#
|
||||
# ext_or_mime_type - A file extension ".txt" or mime type "text/plain".
|
||||
|
||||
@@ -107,7 +107,7 @@ module Linguist
|
||||
#
|
||||
# Returns a content type String.
|
||||
def content_type
|
||||
@content_type ||= Mime.content_type_for(extname)
|
||||
@content_type ||= binary? ? mime_type : 'text/plain'
|
||||
end
|
||||
|
||||
# Public: Is the path binary?
|
||||
|
||||
Reference in New Issue
Block a user