(input, options)
| 348 | } |
| 349 | |
| 350 | export function Request(input, options) { |
| 351 | if (!(this instanceof Request)) { |
| 352 | throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.') |
| 353 | } |
| 354 | |
| 355 | options = options || {} |
| 356 | var body = options.body |
| 357 | |
| 358 | if (input instanceof Request) { |
| 359 | if (input.bodyUsed) { |
| 360 | throw new TypeError('Already read') |
| 361 | } |
| 362 | this.url = input.url |
| 363 | this.credentials = input.credentials |
| 364 | if (!options.headers) { |
| 365 | this.headers = new Headers(input.headers) |
| 366 | } |
| 367 | this.method = input.method |
| 368 | this.mode = input.mode |
| 369 | this.signal = input.signal |
| 370 | if (!body && input._bodyInit != null) { |
| 371 | body = input._bodyInit |
| 372 | input.bodyUsed = true |
| 373 | } |
| 374 | } else { |
| 375 | this.url = String(input) |
| 376 | } |
| 377 | |
| 378 | this.credentials = options.credentials || this.credentials || 'same-origin' |
| 379 | if (options.headers || !this.headers) { |
| 380 | this.headers = new Headers(options.headers) |
| 381 | } |
| 382 | this.method = normalizeMethod(options.method || this.method || 'GET') |
| 383 | this.mode = options.mode || this.mode || null |
| 384 | this.signal = options.signal || this.signal || (function () { |
| 385 | if ('AbortController' in g) { |
| 386 | var ctrl = new AbortController(); |
| 387 | return ctrl.signal; |
| 388 | } |
| 389 | }()); |
| 390 | this.referrer = null |
| 391 | |
| 392 | if ((this.method === 'GET' || this.method === 'HEAD') && body) { |
| 393 | throw new TypeError('Body not allowed for GET or HEAD requests') |
| 394 | } |
| 395 | this._initBody(body) |
| 396 | |
| 397 | if (this.method === 'GET' || this.method === 'HEAD') { |
| 398 | if (options.cache === 'no-store' || options.cache === 'no-cache') { |
| 399 | // Search for a '_' parameter in the query string |
| 400 | var reParamSearch = /([?&])_=[^&]*/ |
| 401 | if (reParamSearch.test(this.url)) { |
| 402 | // If it already exists then set the value with the current time |
| 403 | this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime()) |
| 404 | } else { |
| 405 | // Otherwise add a new '_' parameter to the end with the current time |
| 406 | var reQueryString = /\?/ |
| 407 | this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime() |
no test coverage detected
searching dependent graphs…