Skip to content

Commit

Permalink
infers type based on Content-Type header.
Browse files Browse the repository at this point in the history
closes #70
  • Loading branch information
ded committed Feb 24, 2014
1 parent 3d8b07a commit 2b751d2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
*.sublime-workspace
2 changes: 1 addition & 1 deletion src/copyright.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Reqwest! A general purpose XHR connection manager
* license MIT (c) Dustin Diaz 2013
* license MIT (c) Dustin Diaz 2014
* https://github.com/ded/reqwest
*/
17 changes: 8 additions & 9 deletions src/reqwest.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
if (r._aborted) return error(r.request)
if (r.request && r.request[readyState] == 4) {
r.request.onreadystatechange = noop
if (twoHundo.test(r.request.status))
success(r.request)
if (twoHundo.test(r.request.status)) success(r.request)
else
error(r.request)
}
Expand Down Expand Up @@ -134,9 +133,6 @@
// need this for IE due to out-of-order onreadystatechange(), binding script
// execution to an event listener gives us control over when the script
// is executed. See http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
//
// if this hack is used in IE10 jsonp callback are never called
script.event = 'onclick'
script.htmlFor = script.id = '_reqwest_' + reqId
}

Expand Down Expand Up @@ -223,9 +219,12 @@
init.apply(this, arguments)
}

function setType(url) {
var m = url.match(/\.(json|jsonp|html|xml)(\?|$)/)
return m ? m[1] : 'js'
function setType(header) {
// json, javascript, text/plain, text/html, xml
if (header.match('json')) return 'json'
if (header.match('javascript')) return 'js'
if (header.match('text')) return 'html'
if (header.match('xml')) return 'xml'
}

function init(o, fn) {
Expand All @@ -247,7 +246,6 @@
this._responseArgs = {}

var self = this
, type = o['type'] || setType(this.url)

fn = fn || function () {}

Expand Down Expand Up @@ -284,6 +282,7 @@
}

function success (resp) {
var type = o['type'] || setType(resp.getResponseHeader('Content-Type'))
resp = (type !== 'jsonp') ? self.request : resp
// use global data filter on response text
var filteredResponse = globalSetupOptions.dataFilter(resp.responseText, type)
Expand Down
1 change: 0 additions & 1 deletion use-me.sublime-workspace

This file was deleted.

0 comments on commit 2b751d2

Please sign in to comment.