From f9bb30fc4e0aceed2475b9fd4b68282ada7ca067 Mon Sep 17 00:00:00 2001 From: ryaneof Date: Sat, 28 Feb 2015 16:41:04 +0800 Subject: [PATCH 1/2] add support for file protocol --- fetch.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fetch.js b/fetch.js index d125be8e..c04220e3 100644 --- a/fetch.js +++ b/fetch.js @@ -279,7 +279,8 @@ } xhr.onload = function() { - var status = (xhr.status === 1223) ? 204 : xhr.status + var protocol = /^([\w-]+:)\/\//.test(responseURL()) ? RegExp.$1 : self.location.protocol + var status = ((xhr.status === 1223) || (xhr.status === 0 && protocol === 'file:')) ? 204 : xhr.status if (status < 100 || status > 599) { reject(new TypeError('Network request failed')) return From 0b3c237388ac5bb7de7e20820e1ad0c44ab791c1 Mon Sep 17 00:00:00 2001 From: ryaneof Date: Sat, 28 Feb 2015 17:23:14 +0800 Subject: [PATCH 2/2] pass test case --- fetch.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fetch.js b/fetch.js index c04220e3..12e7b336 100644 --- a/fetch.js +++ b/fetch.js @@ -279,8 +279,7 @@ } xhr.onload = function() { - var protocol = /^([\w-]+:)\/\//.test(responseURL()) ? RegExp.$1 : self.location.protocol - var status = ((xhr.status === 1223) || (xhr.status === 0 && protocol === 'file:')) ? 204 : xhr.status + var status = ((xhr.status === 1223) || (xhr.status === 0 && /^([\w-]+:)\/\//.exec(responseURL())[1] === 'file:')) ? 204 : xhr.status if (status < 100 || status > 599) { reject(new TypeError('Network request failed')) return