From cdc73526a80de2120df7aa44f7dc820df6de789d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 21 Dec 2021 09:39:05 +0100 Subject: [PATCH] media: Add PDF MIME type --- media/mediaType.go | 5 ++++- media/mediaType_test.go | 13 ++++++------- media/testdata/resource.pdf | Bin 0 -> 2830 bytes 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 media/testdata/resource.pdf diff --git a/media/mediaType.go b/media/mediaType.go index 0bdeb6db787..18af666d59a 100644 --- a/media/mediaType.go +++ b/media/mediaType.go @@ -169,7 +169,6 @@ func (m Type) IsText() bool { switch m.SubType { case "javascript", "json", "rss", "xml", "svg", TOMLType.SubType, YAMLType.SubType: return true - } return false } @@ -239,6 +238,9 @@ var ( TrueTypeFontType = newMediaType("font", "ttf", []string{"ttf"}) OpenTypeFontType = newMediaType("font", "otf", []string{"otf"}) + // Common document types + PDFType = newMediaType("application", "pdf", []string{"pdf"}) + // Common video types AVIType = newMediaType("video", "x-msvideo", []string{"avi"}) MPEGType = newMediaType("video", "mpeg", []string{"mpg", "mpeg"}) @@ -282,6 +284,7 @@ var DefaultTypes = Types{ GPPType, OpenTypeFontType, TrueTypeFontType, + PDFType, } func init() { diff --git a/media/mediaType_test.go b/media/mediaType_test.go index f3a06e8ed0c..8c739813d79 100644 --- a/media/mediaType_test.go +++ b/media/mediaType_test.go @@ -51,6 +51,7 @@ func TestDefaultTypes(t *testing.T) { {XMLType, "application", "xml", "xml", "application/xml", "application/xml"}, {TOMLType, "application", "toml", "toml", "application/toml", "application/toml"}, {YAMLType, "application", "yaml", "yaml", "application/yaml", "application/yaml"}, + {PDFType, "application", "pdf", "pdf", "application/pdf", "application/pdf"}, {TrueTypeFontType, "font", "ttf", "ttf", "font/ttf", "font/ttf"}, {OpenTypeFontType, "font", "otf", "otf", "font/otf", "font/otf"}, } { @@ -62,7 +63,7 @@ func TestDefaultTypes(t *testing.T) { } - c.Assert(len(DefaultTypes), qt.Equals, 30) + c.Assert(len(DefaultTypes), qt.Equals, 31) } func TestGetByType(t *testing.T) { @@ -118,7 +119,8 @@ func TestGetFirstBySuffix(t *testing.T) { c.Assert(found, qt.Equals, true) c.Assert(f, qt.Equals, SuffixInfo{ Suffix: suffix, - FullSuffix: "." + suffix}) + FullSuffix: "." + suffix, + }) c.Assert(t, qt.Equals, expectedType) } @@ -126,7 +128,6 @@ func TestGetFirstBySuffix(t *testing.T) { check("json", JSONType) check("geojson", geoJSON) check("gjson", geoJSON) - } func TestFromTypeString(t *testing.T) { @@ -150,7 +151,6 @@ func TestFromTypeString(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(f, qt.Equals, Type{MainType: "text", SubType: "xml", mimeSuffix: ""}) - } func TestFromStringAndExt(t *testing.T) { @@ -178,7 +178,6 @@ func TestFromExtensionMultipleSuffixes(t *testing.T) { c.Assert(found, qt.Equals, true) c.Assert(ftp.String(), qt.Equals, "image/svg+xml") c.Assert(found, qt.Equals, true) - } func TestFromContent(t *testing.T) { @@ -189,7 +188,8 @@ func TestFromContent(t *testing.T) { mtypes := DefaultTypes for _, filename := range files { - c.Run(filepath.Base(filename), func(c *qt.C) { + name := filepath.Base(filename) + c.Run(name, func(c *qt.C) { content, err := ioutil.ReadFile(filename) c.Assert(err, qt.IsNil) ext := strings.TrimPrefix(paths.Ext(filename), ".") @@ -252,7 +252,6 @@ func TestDecodeTypes(t *testing.T) { _, found = tt.GetByType("application/hugo+hg") c.Assert(found, qt.Equals, true) - }, }, { diff --git a/media/testdata/resource.pdf b/media/testdata/resource.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c0e31a076aeb1fa7729e82279943b3504f85338d GIT binary patch literal 2830 zcmd5;-EP}96u#$EoSOg%kdhLuKNm%TIEk^XOA{o|$l$1urA7}G%`-gh0z#{u*ztl%QS<`8GX}hHVSC$ z1#7bpRcRqJ1yrR3rNPc6{H6+9i5xEEbS|`-mS8Ju3MKNA!i6a$Sovfroahu5ZrYbf z$Y~t%wa1;kubKAQ=Lt=Mwosd>USoNma-T;(qRBA&Rz@Q%n4TTOSNCnzYHw71F1>&b zgZ9|!vhOwZ>eU{fA-OMc`Th4>8p!8gxnC!_O6sp|_(!9j!4 zl}rI2*Anp(v6E8TCW$z)#(@?w9K8J>pe)8XYW!;hbAlZxi{j`%A=xgD@m>JvAQ{$i zx+!l~m_<`ypTcJZ@b7hZF-aPQ?eXuN^uL?7r@s%cJHXn!ip%*i%*_h!Ycv4+yhKny zkVPObZIxvdMwJC^EQqpI!qH0D>D+1dx$Ge8QYh?=Y4Q9TxY=LlKA(X{v8k=GuYoxV zbzeBf?vyKQu?=mRpI}SD+lY(UFY12dGL(5vH|f26Pp*%X)OVnw6y0RN{t@%`%+H zQq6RUYqc%x-Dko|I6QmHJumVG9`X#H@aSkehNnViNHu()I11Bz5QX6&1eC8oAFJX% z&>PVZ8B|x~2Z#q<5$8z!x}w1llkSN8@P(Eiz0l$T-}T6Y5TUVSi-*XhS`k48gS4fn tdFze(DqWWB+Te?Dj27AI&pI>6zUm3`FC<{1uysXv><8rF;QVq-{svGq0pkDw literal 0 HcmV?d00001