Skip to content

Commit

Permalink
fixed gz, xml and xsl MIME types and added new ones for HTML5 audio/v…
Browse files Browse the repository at this point in the history
…ideo (closes #368)
  • Loading branch information
kraih committed Aug 6, 2012
1 parent 813d36c commit 307a5db
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 59 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

3.22 2012-08-06
- Added mp4, ogg, ogv and webm MIME types.
- Removed x- prefix from js and woff MIME types.
- Improved documentation.
- Fixed gz, xml and xsl MIME types.

3.21 2012-08-05
- Improved documentation.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/Rendering.pod
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ L<Mojolicious::Controller/"respond_to"> instead of
L<Mojolicious::Controller/"render">.

# /hello (Accept: application/json) -> "json"
# /hello (Accept: text/xml) -> "xml"
# /hello (Accept: application/xml) -> "xml"
# /hello.json -> "json"
# /hello.xml -> "xml"
# /hello?format=json -> "json"
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Lite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ content negotiation you can also use L<Mojolicious::Controller/"respond_to">.
use Mojolicious::Lite;
# /hello (Accept: application/json)
# /hello (Accept: text/xml)
# /hello (Accept: application/xml)
# /hello.json
# /hello.xml
# /hello?format=json
Expand Down
11 changes: 7 additions & 4 deletions lib/Mojolicious/Types.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ has types => sub {
bin => 'application/octet-stream',
css => 'text/css',
gif => 'image/gif',
gz => 'application/gzip',
gz => 'application/x-gzip',
htm => 'text/html',
html => 'text/html;charset=UTF-8',
ico => 'image/x-icon',
Expand All @@ -18,15 +18,18 @@ has types => sub {
js => 'application/javascript',
json => 'application/json',
mp3 => 'audio/mpeg',
mp4 => 'video/mp4',
ogg => 'audio/ogg',
ogv => 'video/ogg',
pdf => 'application/pdf',
png => 'image/png',
rss => 'application/rss+xml',
svg => 'image/svg+xml',
tar => 'application/x-tar',
txt => 'text/plain',
webm => 'video/webm',
woff => 'application/font-woff',
xml => 'text/xml',
xsl => 'text/xml',
xml => 'application/xml',
xsl => 'application/xml',
zip => 'application/zip'
};
};
Expand Down
7 changes: 4 additions & 3 deletions t/mojolicious/exception_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ $t->get_ok('/dead_action')->status_is(500)
like $log, qr/dead action!/, 'right result';

# GET /dead_action.xml (different format)
$t->get_ok('/dead_action.xml')->status_is(500)->content_type_is('text/xml')
->content_is("<very>bad</very>\n");
$t->get_ok('/dead_action.xml')->status_is(500)
->content_type_is('application/xml')->content_is("<very>bad</very>\n");

# GET /dead_action.json (unsupported format)
$t->get_ok('/dead_action.json')->status_is(500)
Expand Down Expand Up @@ -189,7 +189,8 @@ $t->get_ok('/missing_template')->status_is(404)

# GET /missing_template.xml (different format)
$t->get_ok('/missing_template.xml')->status_is(404)
->content_type_is('text/xml')->content_is("<somewhat>bad</somewhat>\n");
->content_type_is('application/xml')
->content_is("<somewhat>bad</somewhat>\n");

# GET /missing_template.json (unsupported format)
$t->get_ok('/missing_template.json')->status_is(404)
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/group_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ $t->get_ok('/one_format')->status_is(404)
->content_type_is('text/html;charset=UTF-8');

# GET /one_format.xml
$t->get_ok('/one_format.xml')->status_is(200)->content_type_is('text/xml')
->content_is('One format.');
$t->get_ok('/one_format.xml')->status_is(200)
->content_type_is('application/xml')->content_is('One format.');

# GET /one_format.txt
$t->get_ok('/one_format.txt')->status_is(404)
Expand Down
89 changes: 47 additions & 42 deletions t/mojolicious/restful_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -158,44 +158,45 @@ $t->get_ok('/rest.json?format=json', {Accept => 'application/json'})
->json_content_is({just => 'works'});

# GET /rest.xml (xml format)
$t->get_ok('/rest.xml')->status_is(200)->content_type_is('text/xml')
$t->get_ok('/rest.xml')->status_is(200)->content_type_is('application/xml')
->text_is(just => 'works');

# GET /rest (accept xml)
$t->get_ok('/rest', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
$t->get_ok('/rest', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest (accept xml again)
$t->get_ok('/rest', {Accept => 'TEXT/XML'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
$t->get_ok('/rest', {Accept => 'APPLICATION/XML'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest.xml (accept xml with format)
$t->get_ok('/rest.xml', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
$t->get_ok('/rest.xml', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest.txt (accept xml with wrong format)
$t->get_ok('/rest.txt', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
$t->get_ok('/rest.txt', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest (accept xml with quality)
$t->get_ok('/rest', {Accept => 'text/xml;q=9'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
$t->get_ok('/rest', {Accept => 'application/xml;q=9'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest (xml query)
$t->get_ok('/rest?format=xml')->status_is(200)->content_type_is('text/xml')
->text_is(just => 'works');
$t->get_ok('/rest?format=xml')->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest (xml format with query)
$t->get_ok('/rest.xml?format=xml')->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest (accept json with query)
$t->get_ok('/rest?format=xml', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
$t->get_ok('/rest?format=xml', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works');

# GET /rest (accept json with everything)
$t->get_ok('/rest.xml?format=xml', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works');
$t->get_ok('/rest.xml?format=xml', {Accept => 'application/xml'})
->status_is(200)->content_type_is('application/xml')
->text_is(just => 'works');

# GET /rest (unsupported accept)
$t->get_ok('/rest', {Accept => 'image/png'})->status_is(204)->content_is('');
Expand Down Expand Up @@ -347,60 +348,64 @@ $t->post_form_ok(
->json_content_is({just => 'works too'});

# POST /rest.xml (xml format)
$t->post_ok('/rest.xml')->status_is(200)->content_type_is('text/xml')
$t->post_ok('/rest.xml')->status_is(200)->content_type_is('application/xml')
->text_is(just => 'works too');

# POST /rest (accept xml)
$t->post_ok('/rest', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_ok('/rest', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (accept xml again)
$t->post_ok('/rest', {Accept => 'TEXT/XML'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_ok('/rest', {Accept => 'APPLICATION/XML'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest.xml (accept xml with format)
$t->post_ok('/rest.xml', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_ok('/rest.xml', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest.txt (accept xml with wrong format)
$t->post_ok('/rest.txt', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_ok('/rest.txt', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (accept xml with quality)
$t->post_ok('/rest', {Accept => 'text/xml;q=9'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_ok('/rest', {Accept => 'application/xml;q=9'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (xml query)
$t->post_ok('/rest?format=xml')->status_is(200)->content_type_is('text/xml')
->text_is(just => 'works too');
$t->post_ok('/rest?format=xml')->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (xml format with query)
$t->post_ok('/rest.xml?format=xml')->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (accept json with query)
$t->post_ok('/rest?format=xml', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_ok('/rest?format=xml', {Accept => 'application/xml'})->status_is(200)
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (accept json with everything)
$t->post_ok('/rest.xml?format=xml', {Accept => 'text/xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_ok('/rest.xml?format=xml', {Accept => 'application/xml'})
->status_is(200)->content_type_is('application/xml')
->text_is(just => 'works too');

# POST /rest (xml form)
$t->post_form_ok('/rest' => {format => 'xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (xml format with form)
$t->post_form_ok('/rest.xml' => {format => 'xml'})->status_is(200)
->content_type_is('text/xml')->text_is(just => 'works too');
->content_type_is('application/xml')->text_is(just => 'works too');

# POST /rest (accept json with form)
$t->post_form_ok('/rest' => {format => 'xml'} => {Accept => 'text/xml'})
->status_is(200)->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_form_ok('/rest' => {format => 'xml'} => {Accept => 'application/xml'})
->status_is(200)->content_type_is('application/xml')
->text_is(just => 'works too');

# POST /rest (accept json with everything, form alternative)
$t->post_form_ok('/rest.xml' => {format => 'xml'} => {Accept => 'text/xml'})
->status_is(200)->content_type_is('text/xml')->text_is(just => 'works too');
$t->post_form_ok(
'/rest.xml' => {format => 'xml'} => {Accept => 'application/xml'})
->status_is(200)->content_type_is('application/xml')
->text_is(just => 'works too');

# POST /rest (unsupported accept)
$t->post_ok('/rest', {Accept => 'image/png'})->status_is(201)
Expand Down
15 changes: 9 additions & 6 deletions t/mojolicious/types.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 43;
use Test::More tests => 46;

# "Your mistletoe is no match for my *tow* missile."
use Mojolicious::Types;
Expand All @@ -17,26 +17,29 @@ is_deeply $t->detect('application/atom+xml'), ['atom'], 'right formats';
is_deeply $t->detect('application/octet-stream'), ['bin'], 'right formats';
is_deeply $t->detect('text/css'), ['css'], 'right formats';
is_deeply $t->detect('image/gif'), ['gif'], 'right formats';
is_deeply $t->detect('application/gzip'), ['gz'], 'right formats';
is_deeply $t->detect('application/x-gzip'), ['gz'], 'right formats';
is_deeply $t->detect('text/html'), ['htm', 'html'], 'right formats';
is_deeply $t->detect('image/x-icon'), ['ico'], 'right formats';
is_deeply $t->detect('image/jpeg'), ['jpeg', 'jpg'], 'right formats';
is_deeply $t->detect('application/javascript'), ['js'], 'right formats';
is_deeply $t->detect('application/json'), ['json'], 'right formats';
is_deeply $t->detect('audio/mpeg'), ['mp3'], 'right formats';
is_deeply $t->detect('video/mp4'), ['mp4'], 'right formats';
is_deeply $t->detect('audio/ogg'), ['ogg'], 'right formats';
is_deeply $t->detect('video/ogg'), ['ogv'], 'right formats';
is_deeply $t->detect('application/pdf'), ['pdf'], 'right formats';
is_deeply $t->detect('image/png'), ['png'], 'right formats';
is_deeply $t->detect('application/rss+xml'), ['rss'], 'right formats';
is_deeply $t->detect('image/svg+xml'), ['svg'], 'right formats';
is_deeply $t->detect('application/x-tar'), ['tar'], 'right formats';
is_deeply $t->detect('text/plain'), ['txt'], 'right formats';
is_deeply $t->detect('video/webm'), ['webm'], 'right formats';
is_deeply $t->detect('application/font-woff'), ['woff'], 'right formats';
is_deeply $t->detect('text/xml'), ['xml', 'xsl'], 'right formats';
is_deeply $t->detect('application/xml'), ['xml', 'xsl'], 'right formats';
is_deeply $t->detect('application/zip'), ['zip'], 'right format';

# Detect special cases
is_deeply $t->detect('Text/Xml'), ['xml', 'xsl'], 'right formats';
is_deeply $t->detect('TEXT/XML'), ['xml', 'xsl'], 'right formats';
is_deeply $t->detect('Application/Xml'), ['xml', 'xsl'], 'right formats';
is_deeply $t->detect('APPLICATION/XML'), ['xml', 'xsl'], 'right formats';
is_deeply $t->detect('text/html;q=0.9'), ['htm', 'html'], 'right formats';
is_deeply $t->detect('text/html,*/*'), [], 'no formats';
is_deeply $t->detect('text/html;q=0.9,*/*'), [], 'no formats';
Expand Down

0 comments on commit 307a5db

Please sign in to comment.