Skip to content

Commit

Permalink
media: Add PDF MIME type
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Dec 22, 2021
1 parent 425c7d9 commit cdc7352
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 4 additions & 1 deletion media/mediaType.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -282,6 +284,7 @@ var DefaultTypes = Types{
GPPType,
OpenTypeFontType,
TrueTypeFontType,
PDFType,
}

func init() {
Expand Down
13 changes: 6 additions & 7 deletions media/mediaType_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
} {
Expand All @@ -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) {
Expand Down Expand Up @@ -118,15 +119,15 @@ 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)
}

check("js", JavascriptType)
check("json", JSONType)
check("geojson", geoJSON)
check("gjson", geoJSON)

}

func TestFromTypeString(t *testing.T) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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), ".")
Expand Down Expand Up @@ -252,7 +252,6 @@ func TestDecodeTypes(t *testing.T) {

_, found = tt.GetByType("application/hugo+hg")
c.Assert(found, qt.Equals, true)

},
},
{
Expand Down
Binary file added media/testdata/resource.pdf
Binary file not shown.

0 comments on commit cdc7352

Please sign in to comment.