提交 60f902de 编写于 作者: J Joshua Peek

Remove private Request._fetch

上级 ab1ac93d
......@@ -244,12 +244,41 @@
return head
}
Request.prototype._fetch = function() {
var self = this
Body.call(Request.prototype)
function Response(bodyInit, options) {
if (!options) {
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 || ''
}
Body.call(Response.prototype)
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function(input, init) {
// TODO: Request constructor should accept input, init
var request
if (Request.prototype.isPrototypeOf(input) && !init) {
request = input
} else {
request = new Request(input, init)
}
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest()
if (self.credentials === 'cors') {
if (request.credentials === 'cors') {
xhr.withCredentials = true;
}
......@@ -286,53 +315,20 @@
reject(new TypeError('Network request failed'))
}
xhr.open(self.method, self.url, true)
xhr.open(request.method, request.url, true)
if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob'
}
self.headers.forEach(function(name, values) {
request.headers.forEach(function(name, values) {
values.forEach(function(value) {
xhr.setRequestHeader(name, value)
})
})
xhr.send(typeof self._bodyInit === 'undefined' ? null : self._bodyInit)
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)
})
}
Body.call(Request.prototype)
function Response(bodyInit, options) {
if (!options) {
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 || ''
}
Body.call(Response.prototype)
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function (input, init) {
var request
if (Request.prototype.isPrototypeOf(input)) {
request = input
} else {
request = new Request(input, init)
}
return request._fetch()
}
self.fetch.polyfill = true
})();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册