- From: Jason Sebring <notifications@github.com>
- Date: Sat, 04 Nov 2017 19:27:47 +0000 (UTC)
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Saturday, 4 November 2017 19:28:10 UTC
# KISS and make up
Here is my duct taped react native version
```
function retch(url, params) {
let xhr = new XMLHttpRequest()
let promise = new Promise((resolve, reject) => {
xhr.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
if (this.status === 200) {
let response = new Response(xhr.response)
response.status = 200
response.ok = true
resolve(response)
}
else reject({ status: this.status })
}
}
const _async = (typeof params.async === 'boolean') ? params.async : true;
xhr.open(params.method || 'GET', url, _async, params.user, params.password)
params.headers && Object.entries(params.headers).forEach(keyValue => {
xhr.setRequestHeader(keyValue[0], keyValue[1])
})
// necessary before making a request
if (typeof params.timeout === 'number')
xhr.timeout = params.timeout
if (typeof params.withCredentials === 'boolean')
xhr.withCredentials = params.withCredentials
xhr.send(params.body)
})
// directly access xmlHttpRequest instead of being "clever"
promise.xmlHttpRequest = xhr
return promise
}
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/27#issuecomment-341923556
Received on Saturday, 4 November 2017 19:28:10 UTC