@@ -78,26 +78,35 @@ def best_match(supported, header):
78
78
# Build list of `MIME types
79
79
# <http://www.iana.org/assignments/media-types/>`_ for HTTP responses.
80
80
# Ported from `Ruby on Rails
81
- # <https://github.com/rails/rails/blob/v3.1.0 /actionpack/lib/action_dispatch/http/mime_types.rb>`_
81
+ # <https://github.com/rails/rails/blob/v5.0.0.1 /actionpack/lib/action_dispatch/http/mime_types.rb>`_
82
82
DEFAULT_TYPES = {
83
- 'all' : ['*/*' ],
84
- 'text' : ['text/plain; charset=utf-8' , 'txt' ],
85
- 'html' : ['text/html; charset=utf-8' ],
86
- 'xhtml' : ['application/xhtml+xml' , 'xhtml' ],
87
- 'xml' : ['application/xml' , 'text/xml' , 'application/x-xml' ],
88
- 'js' : ['text/javascript' , 'application/javascript' ,
89
- 'application/x-javascript' ],
90
- 'css' : ['text/css' ],
91
- 'ics' : ['text/calendar' ],
92
- 'csv' : ['text/csv' ],
93
- 'rss' : ['application/rss+xml' ],
94
- 'atom' : ['application/atom+xml' ],
95
- 'yaml' : ['application/x-yaml' , 'text/yaml' ],
83
+ # (type, alias, ...): [content_type, ...]
84
+ ('all' ,): ['*/*' ],
85
+ ('text' , 'txt' ): ['text/plain; charset=utf-8' ],
86
+ ('html' ,): ['text/html; charset=utf-8' ],
87
+ ('xhtml' ,): ['application/xhtml+xml' ],
88
+ ('js' ,): ['text/javascript' ,
89
+ 'application/javascript' ,
90
+ 'application/x-javascript' ],
91
+ ('css' ,): ['text/css' ],
92
+ ('ics' ,): ['text/calendar' ],
93
+ ('csv' ,): ['text/csv' ],
94
+ ('vcf' ,): ['text/vcard' ],
95
+
96
+ ('xml' ,): ['application/xml' , 'text/xml' , 'application/x-xml' ],
97
+ ('rss' ,): ['application/rss+xml' ],
98
+ ('atom' ,): ['application/atom+xml' ],
99
+ ('yaml' , 'yml' ): ['application/x-yaml' , 'text/yaml' ],
96
100
# just like Rails
97
- 'multipart_form' : ['multipart/form-data' ],
98
- 'url_encoded_form' : ['application/x-www-form-urlencoded' ],
101
+ ( 'multipart_form' ,) : ['multipart/form-data' ],
102
+ ( 'url_encoded_form' ,) : ['application/x-www-form-urlencoded' ],
99
103
# http://www.ietf.org/rfc/rfc4627.txt
100
- 'json' : ['application/json' , 'text/x-json' ]
104
+ # http://www.json.org/JSONRequest.html
105
+ ('json' ,): ['application/json' , 'text/x-json' , 'application/jsonrequest' ],
106
+
107
+ ('pdf' ,): ['application/pdf' ],
108
+ ('zip' ,): ['application/zip' ],
109
+ ('gzip' , 'gz' ): ['application/gzip' ],
101
110
# TODO: https://issues.apache.org/jira/browse/COUCHDB-1261
102
111
# 'kml', 'application/vnd.google-earth.kml+xml',
103
112
# 'kmz', 'application/vnd.google-earth.kmz'
@@ -113,8 +122,9 @@ def __init__(self):
113
122
self .funcs_by_key = OrderedDict ()
114
123
self ._resp_content_type = None
115
124
116
- for k , v in DEFAULT_TYPES .items ():
117
- self .register_type (k , * v )
125
+ for types , v in DEFAULT_TYPES .items ():
126
+ for type_ in types :
127
+ self .register_type (type_ , * v )
118
128
119
129
def is_provides_used (self ):
120
130
"""Checks if any provides function is registered."""
@@ -135,21 +145,33 @@ def register_type(self, key, *args):
135
145
136
146
Predefined types:
137
147
- all: ``*/*``
138
- - text: ``text/plain; charset=utf-8``, ``txt``
148
+ - text: ``text/plain; charset=utf-8``
149
+ - txt: alias of ``text``
139
150
- html: ``text/html; charset=utf-8``
140
- - xhtml: ``application/xhtml+xml``, ``xhtml``
141
- - xml: ``application/xml``, ``text/xml``, ``application/x-xml``
151
+ - xhtml: ``application/xhtml+xml``
142
152
- js: ``text/javascript``, ``application/javascript``,
143
153
``application/x-javascript``
144
154
- css: ``text/css``
145
155
- ics: ``text/calendar``
146
156
- csv: ``text/csv``
157
+ - vcf: ``text/vcard``,
158
+
159
+ - xml: ``application/xml``, ``text/xml``, ``application/x-xml``
147
160
- rss: ``application/rss+xml``
148
161
- atom: ``application/atom+xml``
149
162
- yaml: ``application/x-yaml``, ``text/yaml``
163
+ - yml: alias of ``yaml``
164
+
150
165
- multipart_form: ``multipart/form-data``
151
166
- url_encoded_form: ``application/x-www-form-urlencoded``
152
- - json: ``application/json``, ``text/x-json``
167
+
168
+ - json: ``application/json``, ``text/x-json``,
169
+ ``application/jsonrequest``
170
+
171
+ - pdf: ``application/pdf``
172
+ - zip: ``application/zip``
173
+ - gzip: ``application/gzip``
174
+ - gz: alias of ``gzip``
153
175
154
176
Example:
155
177
>>> register_type('png', 'image/png')
0 commit comments