1Mojolicious::Types(3) User Contributed Perl DocumentationMojolicious::Types(3)
2
3
4

NAME

6       Mojolicious::Types - MIME types
7

SYNOPSIS

9         use Mojolicious::Types;
10
11         my $types = Mojolicious::Types->new;
12         $types->type(foo => 'text/foo');
13         say $types->type('foo');
14

DESCRIPTION

16       Mojolicious::Types manages MIME types for Mojolicious.
17
18         appcache -> text/cache-manifest
19         atom     -> application/atom+xml
20         bin      -> application/octet-stream
21         css      -> text/css
22         gif      -> image/gif
23         gz       -> application/x-gzip
24         htm      -> text/html
25         html     -> text/html;charset=UTF-8
26         ico      -> image/x-icon
27         jpeg     -> image/jpeg
28         jpg      -> image/jpeg
29         js       -> application/javascript
30         json     -> application/json;charset=UTF-8
31         mp3      -> audio/mpeg
32         mp4      -> video/mp4
33         ogg      -> audio/ogg
34         ogv      -> video/ogg
35         pdf      -> application/pdf
36         png      -> image/png
37         rss      -> application/rss+xml
38         svg      -> image/svg+xml
39         txt      -> text/plain;charset=UTF-8
40         webm     -> video/webm
41         woff     -> font/woff
42         woff2    -> font/woff2
43         xml      -> application/xml,text/xml
44         zip      -> application/zip
45
46       The most common ones are already defined.
47

ATTRIBUTES

49       Mojolicious::Types implements the following attributes.
50
51   mapping
52         my $mapping = $types->mapping;
53         $types      = $types->mapping({png => ['image/png']});
54
55       MIME type mapping.
56

METHODS

58       Mojolicious::Types inherits all methods from Mojo::Base and implements
59       the following new ones.
60
61   content_type
62         $types->content_type(Mojolicious::Controller->new, {ext => 'json'});
63
64       Detect MIME type for Mojolicious::Controller object unless a
65       "Content-Type" response header has already been set, defaults to using
66       "application/octet-stream" if no better alternative could be found.
67       Note that this method is EXPERIMENTAL and might change without warning!
68
69       These options are currently available:
70
71       ext
72           ext => 'json'
73
74         File extension to get MIME type for.
75
76       file
77           file => 'foo/bar.png'
78
79         File path to get MIME type for.
80
81   detect
82         my $exts = $types->detect('text/html, application/json;q=9');
83
84       Detect file extensions from "Accept" header value.
85
86         # List detected extensions prioritized
87         say for @{$types->detect('application/json, text/xml;q=0.1', 1)};
88
89   file_type
90         my $type = $types->file_type('foo/bar.png');
91
92       Get MIME type for file path. Note that this method is EXPERIMENTAL and
93       might change without warning!
94
95   type
96         my $type = $types->type('png');
97         $types   = $types->type(png => 'image/png');
98         $types   = $types->type(json => ['application/json', 'text/x-json']);
99
100       Get or set MIME types for file extension, alternatives are only used
101       for detection.
102

SEE ALSO

104       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
105
106
107
108perl v5.30.1                      2020-01-30             Mojolicious::Types(3)
Impressum