Skip to content

Commit

Permalink
#160 Fix problem where no specificed content-type throws exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley Walser committed Aug 5, 2015
1 parent b4171a0 commit 84e0013
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions make/tests.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var routes = {
delayed.pipe(res) delayed.pipe(res)
}, 2000) }, 2000)
}, },
'/tests/204': function(req, res) {
res.writeHead(204);
res.end();
},
'(([\\w\\-\\/\\.]+)\\.(css|js|json|jsonp|html|xml)$)': function (req, res, next, uri, file, ext) { '(([\\w\\-\\/\\.]+)\\.(css|js|json|jsonp|html|xml)$)': function (req, res, next, uri, file, ext) {
res.writeHead(200, { res.writeHead(200, {
'Expires': 0 'Expires': 0
Expand Down
1 change: 1 addition & 0 deletions src/reqwest.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@


function setType(header) { function setType(header) {
// json, javascript, text/plain, text/html, xml // json, javascript, text/plain, text/html, xml
if (header === null) return undefined; //In case of no content-type.
if (header.match('json')) return 'json' if (header.match('json')) return 'json'
if (header.match('javascript')) return 'js' if (header.match('javascript')) return 'js'
if (header.match('text')) return 'html' if (header.match('text')) return 'html'
Expand Down
9 changes: 9 additions & 0 deletions tests/tests.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -801,6 +801,15 @@
}) })
}) })


test('standard mode on no content-type', function (complete) {
ajax({
url: '/tests/204'
, success: function (resp) {
ok(true, 'Nothing blew up.')
}
})
})

test('compat mode "dataType=json" headers', function (complete) { test('compat mode "dataType=json" headers', function (complete) {
ajax.compat({ ajax.compat({
url: '/tests/none.json?echo' url: '/tests/none.json?echo'
Expand Down

0 comments on commit 84e0013

Please sign in to comment.