Skip to content

Commit

Permalink
Reverted commit D3503958
Browse files Browse the repository at this point in the history
Summary:
Fixes facebook#6679
Closes facebook#8512

Differential Revision: D3503958

Pulled By: donyu

fbshipit-source-id: f2102c1051fb3fe1d55ecfa24bed19c8d25224e9
  • Loading branch information
bestander authored and Morgan Pretty committed Aug 24, 2016
1 parent 75624d1 commit 7f23cb9
Showing 1 changed file with 26 additions and 73 deletions.
99 changes: 26 additions & 73 deletions Libraries/Fetch/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 = {}

Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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

Expand All @@ -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)) {
Expand All @@ -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')
}
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -382,7 +334,6 @@ var self = {};
this.url = options.url || ''
this._initBody(bodyInit)
}

Body.call(Response.prototype)

Response.prototype.clone = function() {
Expand Down Expand Up @@ -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) {
Expand All @@ -435,28 +386,30 @@ 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))
}

xhr.onerror = function() {
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') {
Expand Down

0 comments on commit 7f23cb9

Please sign in to comment.