Reverted commit D3503958

Summary:
Fixes https://github.com/facebook/react-native/issues/6679
Closes https://github.com/facebook/react-native/pull/8512

Differential Revision: D3503958

Pulled By: donyu

fbshipit-source-id: f2102c1051fb3fe1d55ecfa24bed19c8d25224e9
This commit is contained in:
Konstantin Raev 2016-07-01 12:58:03 -07:00 committed by Facebook Github Bot 8
parent 6424c8b2e0
commit 2eed7e7429

View File

@ -8,8 +8,6 @@
*
* This is a third-party polyfill grabbed from:
* https://github.com/github/fetch
* copied from v1.0.0
* https://github.com/github/fetch/commit/4bde61788365cfd3d6155eee8aed3c7673d299d5
*
* @providesModule fetch
* @nolint
@ -50,21 +48,6 @@ var self = {};
return
}
var support = {
searchParams: 'URLSearchParams' in self,
iterable: 'Symbol' in self && 'iterator' in Symbol,
blob: 'FileReader' in self && 'Blob' in self && (function() {
try {
new Blob()
return true
} catch(e) {
return false
}
})(),
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self
}
function normalizeName(name) {
if (typeof name !== 'string') {
name = String(name)
@ -82,24 +65,6 @@ var self = {};
return value
}
// Build a destructive iterator for the value list
function iteratorFor(items) {
var iterator = {
next: function() {
var value = items.shift()
return {done: value === undefined, value: value}
}
}
if (support.iterable) {
iterator[Symbol.iterator] = function() {
return iterator
}
}
return iterator
}
function Headers(headers) {
this.map = {}
@ -155,28 +120,6 @@ var self = {};
}, this)
}
Headers.prototype.keys = function() {
var items = []
this.forEach(function(value, name) { items.push(name) })
return iteratorFor(items)
}
Headers.prototype.values = function() {
var items = []
this.forEach(function(value) { items.push(value) })
return iteratorFor(items)
}
Headers.prototype.entries = function() {
var items = []
this.forEach(function(value, name) { items.push([name, value]) })
return iteratorFor(items)
}
if (support.iterable) {
Headers.prototype[Symbol.iterator] = Headers.prototype.entries
}
function consumed(body) {
if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read'))
@ -207,6 +150,19 @@ var self = {};
return fileReaderReady(reader)
}
var support = {
blob: typeof FileReader === 'function' && typeof Blob === 'function' && (function() {
try {
new Blob();
return true
} catch(e) {
return false
}
})(),
formData: typeof FormData === 'function',
arrayBuffer: typeof ArrayBuffer === 'function'
}
function Body() {
this.bodyUsed = false
@ -218,8 +174,6 @@ var self = {};
this._bodyBlob = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this._bodyText = body.toString()
} else if (!body) {
this._bodyText = ''
} else if (support.arrayBuffer && ArrayBuffer.prototype.isPrototypeOf(body)) {
@ -234,8 +188,6 @@ var self = {};
this.headers.set('content-type', 'text/plain;charset=UTF-8')
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type)
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
}
}
}
@ -357,7 +309,7 @@ var self = {};
function headers(xhr) {
var head = new Headers()
var pairs = (xhr.getAllResponseHeaders() || '').trim().split('\n')
var pairs = xhr.getAllResponseHeaders().trim().split('\n')
pairs.forEach(function(header) {
var split = header.trim().split(':')
var key = split.shift().trim()
@ -382,7 +334,6 @@ var self = {};
this.url = options.url || ''
this._initBody(bodyInit)
}
Body.call(Response.prototype)
Response.prototype.clone = function() {
@ -410,9 +361,9 @@ var self = {};
return new Response(null, {status: status, headers: {location: url}})
}
self.Headers = Headers
self.Request = Request
self.Response = Response
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function(input, init) {
return new Promise(function(resolve, reject) {
@ -435,17 +386,23 @@ var self = {};
return xhr.getResponseHeader('X-Request-URL')
}
return
return;
}
xhr.onload = function() {
var status = (xhr.status === 1223) ? 204 : xhr.status
if (status < 100 || status > 599) {
reject(new TypeError('Network request failed'))
return
}
var options = {
status: xhr.status,
status: status,
statusText: xhr.statusText,
headers: headers(xhr),
url: responseURL()
}
var body = 'response' in xhr ? xhr.response : xhr.responseText
var body = 'response' in xhr ? xhr.response : xhr.responseText;
resolve(new Response(body, options))
}
@ -453,10 +410,6 @@ var self = {};
reject(new TypeError('Network request failed'))
}
xhr.ontimeout = function() {
reject(new TypeError('Network request failed'))
}
xhr.open(request.method, request.url, true)
if (request.credentials === 'include') {