fix merge conflicts for #1610

This commit is contained in:
Leo 2017-02-23 18:41:46 -05:00
commit e019c8131c
6 changed files with 155 additions and 57 deletions

View file

@ -2,6 +2,8 @@
var buildQueryString = require("../querystring/build")
var FILE_PROTOCOL_REGEX = new RegExp('^file://', 'i')
module.exports = function($window, Promise) {
var callbackCount = 0
@ -53,7 +55,16 @@ module.exports = function($window, Promise) {
if (useBody) args.data = args.serialize(args.data)
else args.url = assemble(args.url, args.data)
var xhr = new $window.XMLHttpRequest()
var xhr = new $window.XMLHttpRequest(),
aborted = false,
_abort = xhr.abort
xhr.abort = function abort() {
aborted = true
_abort.call(xhr)
}
xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined)
if (args.serialize === JSON.stringify && useBody) {
@ -71,12 +82,13 @@ module.exports = function($window, Promise) {
if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
xhr.onreadystatechange = function() {
// Don't throw errors on xhr.abort(). XMLHttpRequests ends up in a state of
// xhr.status == 0 and xhr.readyState == 4 if aborted after open, but before completion.
if (xhr.status && xhr.readyState === 4) {
// Don't throw errors on xhr.abort().
if(aborted) return
if (xhr.readyState === 4) {
try {
var response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args))
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || FILE_PROTOCOL_REGEX.test(args.url)) {
resolve(cast(args.type, response))
}
else {