()
| 220 | } |
| 221 | |
| 222 | function Body() { |
| 223 | this.bodyUsed = false |
| 224 | |
| 225 | this._initBody = function(body) { |
| 226 | /* |
| 227 | fetch-mock wraps the Response object in an ES6 Proxy to |
| 228 | provide useful test harness features such as flush. However, on |
| 229 | ES5 browsers without fetch or Proxy support pollyfills must be used; |
| 230 | the proxy-pollyfill is unable to proxy an attribute unless it exists |
| 231 | on the object before the Proxy is created. This change ensures |
| 232 | Response.bodyUsed exists on the instance, while maintaining the |
| 233 | semantic of setting Request.bodyUsed in the constructor before |
| 234 | _initBody is called. |
| 235 | */ |
| 236 | // eslint-disable-next-line no-self-assign |
| 237 | this.bodyUsed = this.bodyUsed |
| 238 | this._bodyInit = body |
| 239 | if (!body) { |
| 240 | this._noBody = true; |
| 241 | this._bodyText = '' |
| 242 | } else if (typeof body === 'string') { |
| 243 | this._bodyText = body |
| 244 | } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { |
| 245 | this._bodyBlob = body |
| 246 | } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { |
| 247 | this._bodyFormData = body |
| 248 | } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { |
| 249 | this._bodyText = body.toString() |
| 250 | } else if (support.arrayBuffer && support.blob && isDataView(body)) { |
| 251 | this._bodyArrayBuffer = bufferClone(body.buffer) |
| 252 | // IE 10-11 can't handle a DataView body. |
| 253 | this._bodyInit = new Blob([this._bodyArrayBuffer]) |
| 254 | } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) { |
| 255 | this._bodyArrayBuffer = bufferClone(body) |
| 256 | } else { |
| 257 | this._bodyText = body = Object.prototype.toString.call(body) |
| 258 | } |
| 259 | |
| 260 | if (!this.headers.get('content-type')) { |
| 261 | if (typeof body === 'string') { |
| 262 | this.headers.set('content-type', 'text/plain;charset=UTF-8') |
| 263 | } else if (this._bodyBlob && this._bodyBlob.type) { |
| 264 | this.headers.set('content-type', this._bodyBlob.type) |
| 265 | } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { |
| 266 | this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8') |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if (support.blob) { |
| 272 | this.blob = function() { |
| 273 | var rejected = consumed(this) |
| 274 | if (rejected) { |
| 275 | return rejected |
| 276 | } |
| 277 | |
| 278 | if (this._bodyBlob) { |
| 279 | return Promise.resolve(this._bodyBlob) |
nothing calls this directly
no test coverage detected
searching dependent graphs…