Summary:This fixes https://github.com/facebook/react-native/issues/6326 with updating https://github.com/facebook/react-native/blob/master/Libraries/Fetch/fetch.js to latest from  https://github.com/github/fetch.

cc skevy steveluscher
Closes https://github.com/facebook/react-native/pull/6347

Differential Revision: D3024308

Pulled By: davidaurelio

fb-gh-sync-id: da87827b94d683aeb66be345e255bd771fdba1be
shipit-source-id: da87827b94d683aeb66be345e255bd771fdba1be
This commit is contained in:
Laurence Bortfeld 2016-03-08 09:47:56 -08:00 committed by Facebook Github Bot 2
parent 10e990f415
commit 87c26885a3
1 changed files with 40 additions and 21 deletions

View File

@ -159,13 +159,13 @@ var self = {};
return false
}
})(),
formData: typeof FormData === 'function'
formData: typeof FormData === 'function',
arrayBuffer: typeof ArrayBuffer === 'function'
}
function Body() {
this.bodyUsed = false
this._initBody = function(body) {
this._bodyInit = body
if (typeof body === 'string') {
@ -176,9 +176,20 @@ var self = {};
this._bodyFormData = body
} else if (!body) {
this._bodyText = ''
} else if (support.arrayBuffer && ArrayBuffer.prototype.isPrototypeOf(body)) {
// Only support ArrayBuffers for POST method.
// Receiving ArrayBuffers happens via Blobs, instead.
} else {
throw new Error('unsupported BodyInit type')
}
if (!this.headers.get('content-type')) {
if (typeof body === 'string') {
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)
}
}
}
if (support.blob) {
@ -315,15 +326,15 @@ var self = {};
options = {}
}
this._initBody(bodyInit)
this.type = 'default'
this.url = null
this.status = options.status
this.ok = this.status >= 200 && this.status < 300
this.statusText = options.statusText
this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers)
this.url = options.url || ''
this._initBody(bodyInit)
}
Body.call(Response.prototype)
Response.prototype.clone = function() {
return new Response(this._bodyInit, {
@ -334,13 +345,28 @@ var self = {};
})
}
Body.call(Response.prototype)
Response.error = function() {
var response = new Response(null, {status: 0, statusText: ''})
response.type = 'error'
return response
}
var redirectStatuses = [301, 302, 303, 307, 308]
Response.redirect = function(url, status) {
if (redirectStatuses.indexOf(status) === -1) {
throw new RangeError('Invalid status code')
}
return new Response(null, {status: status, headers: {location: url}})
}
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function(input, init) {
return new Promise(function(resolve, reject) {
var request
if (Request.prototype.isPrototypeOf(input) && !init) {
request = input
@ -348,7 +374,6 @@ var self = {};
request = new Request(input, init)
}
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest()
function responseURL() {
@ -365,13 +390,8 @@ var self = {};
}
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: status,
status: xhr.status,
statusText: xhr.statusText,
headers: headers(xhr),
url: responseURL()
@ -405,5 +425,4 @@ var self = {};
})();
/** End of the third-party code */
module.exports = self;