@@ -11,7 +11,15 @@ defmodule MIME do
11
11
12
12
Note that defining a new type will completely override all
13
13
previous extensions. You can use `MIME.extensions/1` to get
14
- the existing extension to add whenever defining.
14
+ the existing extension to keep when redefining.
15
+
16
+ You can also customize the extensions for suffixes. For example,
17
+ the mime type "application/custom+gzip" returns the extension
18
+ `".gz"` because the suffix "gzip" maps to `["gz"]`:
19
+
20
+ config :mime, :suffixes, %{
21
+ "gzip" => ["gz"]
22
+ }
15
23
16
24
After adding the configuration, MIME needs to be recompiled
17
25
if you are using an Elixir version earlier than v1.15. In such
@@ -117,14 +125,6 @@ defmodule MIME do
117
125
"video/x-msvideo" => [ "avi" ]
118
126
}
119
127
120
- #selected from https://www.iana.org/assignments/media-type-structured-suffix/media-type-structured-suffix.xhtml
121
- suffixes = % {
122
- "gzip" => [ "gz" ] ,
123
- "json" => [ "json" ] ,
124
- "xml" => [ "xml" ] ,
125
- "zip" => [ "zip" ]
126
- }
127
-
128
128
require Application
129
129
custom_types = Application . compile_env ( :mime , :types , % { } )
130
130
@@ -148,6 +148,18 @@ defmodule MIME do
148
148
raise "conflicting MIMEs for extension .#{ ext } , please override: #{ inspect ( mimes ) } "
149
149
end
150
150
151
+
152
+ # https://www.iana.org/assignments/media-type-structured-suffix/media-type-structured-suffix.xhtml
153
+ default_suffixes = % {
154
+ "gzip" => [ "gz" ] ,
155
+ "json" => [ "json" ] ,
156
+ "xml" => [ "xml" ] ,
157
+ "zip" => [ "zip" ]
158
+ }
159
+
160
+ custom_suffixes = Application . compile_env ( :mime , :suffixes , % { } )
161
+ suffixes = Map . merge ( default_suffixes , custom_suffixes )
162
+
151
163
@ doc """
152
164
Returns the custom types compiled into the MIME module.
153
165
"""
0 commit comments