()
| 7707 | } |
| 7708 | |
| 7709 | function Body() { |
| 7710 | this.bodyUsed = false |
| 7711 | |
| 7712 | this._initBody = function(body) { |
| 7713 | this._bodyInit = body |
| 7714 | if (!body) { |
| 7715 | this._bodyText = '' |
| 7716 | } else if (typeof body === 'string') { |
| 7717 | this._bodyText = body |
| 7718 | } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { |
| 7719 | this._bodyBlob = body |
| 7720 | } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { |
| 7721 | this._bodyFormData = body |
| 7722 | } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { |
| 7723 | this._bodyText = body.toString() |
| 7724 | } else if (support.arrayBuffer && support.blob && isDataView(body)) { |
| 7725 | this._bodyArrayBuffer = bufferClone(body.buffer) |
| 7726 | // IE 10-11 can't handle a DataView body. |
| 7727 | this._bodyInit = new Blob([this._bodyArrayBuffer]) |
| 7728 | } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) { |
| 7729 | this._bodyArrayBuffer = bufferClone(body) |
| 7730 | } else { |
| 7731 | throw new Error('unsupported BodyInit type') |
| 7732 | } |
| 7733 | |
| 7734 | if (!this.headers.get('content-type')) { |
| 7735 | if (typeof body === 'string') { |
| 7736 | this.headers.set('content-type', 'text/plain;charset=UTF-8') |
| 7737 | } else if (this._bodyBlob && this._bodyBlob.type) { |
| 7738 | this.headers.set('content-type', this._bodyBlob.type) |
| 7739 | } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { |
| 7740 | this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8') |
| 7741 | } |
| 7742 | } |
| 7743 | } |
| 7744 | |
| 7745 | if (support.blob) { |
| 7746 | this.blob = function() { |
| 7747 | var rejected = consumed(this) |
| 7748 | if (rejected) { |
| 7749 | return rejected |
| 7750 | } |
| 7751 | |
| 7752 | if (this._bodyBlob) { |
| 7753 | return Promise.resolve(this._bodyBlob) |
| 7754 | } else if (this._bodyArrayBuffer) { |
| 7755 | return Promise.resolve(new Blob([this._bodyArrayBuffer])) |
| 7756 | } else if (this._bodyFormData) { |
| 7757 | throw new Error('could not read FormData body as blob') |
| 7758 | } else { |
| 7759 | return Promise.resolve(new Blob([this._bodyText])) |
| 7760 | } |
| 7761 | } |
| 7762 | |
| 7763 | this.arrayBuffer = function() { |
| 7764 | if (this._bodyArrayBuffer) { |
| 7765 | return consumed(this) || Promise.resolve(this._bodyArrayBuffer) |
| 7766 | } else { |
nothing calls this directly
no test coverage detected