blob: b63d1d82c72b263c31209974f59627564f3c0a31 [file] [log] [blame]
'use strict';(function(e){function B(a){"string"!==typeof a&&(a=String(a));if(/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(a))throw new d("Invalid character in header field name");return a.toLowerCase()}function O(a){"string"!==typeof a&&(a=String(a));var b;var c=0;for(b=a.length;c<b;c++){var f=a.charCodeAt(c);if(9!==f&&10!==f&&13!==f&&32!==f)break}for(b=a.length-1;b>c&&(f=a.charCodeAt(b),9===f||10===f||13===f||32===f);b--);a=a.substring(c,b+1);c=0;for(b=a.length;c<b;c++)if(f=a.charCodeAt(c),256<=f||0===f||
10===f||13===f)throw new d("Invalid character in header field value");return a}function U(a,b){throw new d("Immutable header cannot be modified");}function V(a,b){return!1}function W(a,b){a=a.toLowerCase();return-1<X.indexOf(a)||a.startsWith("proxy-")||a.startsWith("sec-")?!0:!1}function Y(a,b){a=a.toLowerCase();return-1<Z.indexOf(a)||"content-type"===a&&(b=b.split(";")[0].toLowerCase(),-1<aa.indexOf(b))?!1:!0}function J(a,b){return-1<ba.indexOf(a.toLowerCase())?!0:!1}function h(a){this[l]=new G;
void 0===this[u]&&(this[u]=V);if(void 0!==a){if(null===a||"object"!==typeof a)throw new d("Constructing Headers with invalid parameters");a instanceof h?a.forEach(function(a,c){this.append(c,a)},this):C.isArray(a)?a.forEach(function(a){if(2!==a.length)throw new d("Constructing Headers with invalid parameters");this.append(a[0],a[1])},this):Object.getOwnPropertyNames(a).forEach(function(b){this.append(b,a[b])},this)}}function D(a,b){var c=ca(h.prototype);c[u]=b;h.call(c,a);return c}function K(a){if(a.bodyUsed)return E.reject(new d("Body was already read"));
if(null===a.body)return E.resolve(new t(0));if(da(a.body))return E.reject(new d("ReadableStream was already locked"));var b=a.body.getReader(),c=[],f=0;return b.read().then(function ea(a){if(a.done){if(0===c.length)a=new t(0);else if(1===c.length)a=new t(c[0].buffer);else{a=new t(f);for(var k=0,e=c.length,g=0;k<e;k++)a.set(c[k],g),g+=c[k].length}return a}return a.value instanceof t?(f+=a.value.length,c.push(a.value),b.read().then(ea)):E.reject(new d("Invalid stream data type"))})}function P(){this._initBody=
function(a){this[L]=!1;this[n]=null===a||void 0===a?null:a instanceof M?a:new M({start:function(b){if(a)if("string"===typeof a)b.enqueue(FetchInternal.encodeToUTF8(a));else if(Q.prototype.isPrototypeOf(a))b.enqueue(new t(a.slice(0)));else if(fa(a))b.enqueue(new t(a.buffer.slice(0)));else if(a instanceof Blob)b.enqueue(new t(FetchInternal.blobToArrayBuffer(a)));else throw new d("Unsupported BodyInit type");b.close()}});this[p].get("content-type")||("string"===typeof a?this[p].set("content-type","text/plain;charset=UTF-8"):
a instanceof Blob&&""!==a.type&&this[p].set("content-type",a.type))};N(this,{body:{get:function(){return this[n]}},bodyUsed:{get:function(){return this[L]?!0:this[n]?!!ha(this[n]):!1}}});this.arrayBuffer=function(){return K(this).then(function(a){return a.buffer})};this.text=function(){return K(this).then(function(a){return FetchInternal.decodeFromUTF8(a)})};this.json=function(){return this.text().then(JSON.parse)};return this}function v(a,b){var c=void 0!==b&&null!==b&&void 0===b.cloneBody;b=b||
{};var f=b.body||b.cloneBody,e=b.headers;if(a instanceof v){if(a.bodyUsed)throw new d("Request body was already read");this[w]=a.url;this[y]=a.cache;this[z]=a.credentials;void 0===e&&(e=a.headers);this[A]=a.integrity;this[x]=a.method;this[m]=a.mode;c&&"navigate"===this[m]&&(this[m]="same-origin");this[F]=a.redirect;f||null===a.body||(f=a.body,a[L]=!0)}else{this[w]=String(a);if(!FetchInternal.isUrlValid(this[w],!1))throw new d("Invalid request URL");this[m]="cors";this[z]="omit"}if(void 0!==b.window&&
null!==b.window)throw new d("Invalid request window");this[y]=b.cache||this[y]||"default";if(-1===ia.indexOf(this[y]))throw new d("Invalid request cache mode");this[z]=b.credentials||this[z]||"omit";if(-1===ja.indexOf(this[z]))throw new d("Invalid request credentials");void 0!==b.integrity?this[A]=b.integrity:void 0===this[A]&&(this[A]="");a=(b.method||this[x]||"GET").toUpperCase();if(-1===ka.indexOf(a))throw new d("Invalid request method");this[x]=a;if(b.mode&&-1===la.indexOf(b.mode))throw new d("Invalid request mode");
this[m]=b.mode||this[m]||"no-cors";if("no-cors"===this[m]){if(-1===ma.indexOf(this[x]))throw new d("Invalid request method for no-cors");if(""!==this[A])throw new d("Request integrity data is not allowed with no-cors");}if("same-origin"!==this[m]&&"only-if-cached"===this[y])throw new d("Request mode must be same-origin for only-if-cached");this[F]=b.redirect||this[F]||"follow";if(-1===na.indexOf(this[F]))throw new d("Invalid request redirect mode");this[p]="no-cors"===this[m]?D(e,Y):D(e,W);if(("GET"===
this[x]||"HEAD"===this[x])&&f)throw new d("Request body is not allowed for GET or HEAD");this._initBody(f)}function oa(a,b){var c=D(void 0,b);a.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(a){var b=a.split(":");if(a=b.shift().trim())b=b.join(":").trim(),c.append(a,b)});return c}function q(a,b){b||(b={});this[H]="default";this[r]="status"in b?b.status:200;if(200>this[r]||599<this[r])throw new R("Invalid response status");this[S]=200<=this[r]&&300>this[r];if("statusText"in b){var c=b.statusText;
for(var f=0,e=c.length,g;f<e;f++)if(g=c.charCodeAt(f),9!==g&&(32>g||255<g||127===g))throw d("Invalid response status text");}else c="OK";this[I]=c;this[p]=D(b.headers,J);this[w]=b.url||"";if(a&&-1<pa.indexOf(this[r]))throw new d("Response body is not allowed with a null body status");this._initBody(a)}if(!e.fetch){var C=e.Array,Q=e.ArrayBuffer,ca=e.Object.create,N=e.Object.defineProperties,g=e.Symbol,qa=g.iterator,G=e.Map,R=e.RangeError,d=e.TypeError,t=e.Uint8Array,E=e.Promise,M=e.ReadableStream,
T=e.ReadableStreamTee,ha=e.IsReadableStreamDisturbed,da=e.IsReadableStreamLocked,n=g("body"),L=g("bodyUsed"),y=g("cache"),z=g("credentials"),u=g("guardCallback"),p=g("headers"),A=g("integrity"),l=g("map"),x=g("method"),m=g("mode"),S=g("ok"),F=g("redirect"),r=g("status"),I=g("statusText"),H=g("type"),w=g("url"),X="accept-charset accept-encoding access-control-request-headers access-control-request-method connection content-length cookie cookie2 date dnt expect host keep-alive origin referer te trailer transfer-encoding upgrade via".split(" "),
ba=["set-cookie","set-cookie2"],Z=["accept","accept-language","content-language"],aa=["application/x-www-form-urlencoded","multipart/form-data","text/plain"],ia="default no-store reload no-cache force-cache only-if-cached".split(" "),ja=["omit","same-origin","include"],ka="DELETE GET HEAD OPTIONS POST PUT".split(" "),ma=["GET","HEAD","POST"],la=["same-origin","no-cors","cors"],na=["follow","error","manual"],pa=[101,204,205,304],ra=[301,302,303,307,308],sa="[object Int8Array];[object Uint8Array];[object Uint8ClampedArray];[object Int16Array];[object Uint16Array];[object Int32Array];[object Uint32Array];[object Float32Array];[object Float64Array]".split(";"),
fa=Q.isView||function(a){return a&&-1<sa.indexOf(Object.prototype.toString.call(a))};h.prototype.append=function(a,b){if(2!==arguments.length)throw d("Invalid parameters to append");a=B(a);b=O(b);this[u](a,b)||(this[l].has(a)?this[l].set(a,this[l].get(a)+", "+b):this[l].set(a,b))};h.prototype["delete"]=function(a){if(1!==arguments.length)throw d("Invalid parameters to delete");this[u](a,"invalid")||this[l].delete(B(a))};h.prototype.get=function(a){if(1!==arguments.length)throw d("Invalid parameters to get");
a=B(a);var b=this[l].get(a);return void 0!==b?b:null};h.prototype.has=function(a){if(1!==arguments.length)throw d("Invalid parameters to has");return this[l].has(B(a))};h.prototype.set=function(a,b){if(2!==arguments.length)throw d("Invalid parameters to set");a=B(a);b=O(b);this[u](a,b)||this[l].set(a,b)};h.prototype.forEach=function(a,b){var c=this;C.from(this[l].entries()).sort().forEach(function(d){a.call(b,d[1],d[0],c)})};h.prototype.keys=function(){return(new G(C.from(this[l].entries()).sort())).keys()};
h.prototype.values=function(){return(new G(C.from(this[l].entries()).sort())).values()};h.prototype.entries=function(){return(new G(C.from(this[l].entries()).sort())).entries()};h.prototype[qa]=h.prototype.entries;v.prototype.clone=function(){var a=null;null!==this[n]&&(a=T(this[n],!0),this[n]=a[0],a=a[1]);return new v(this,{cloneBody:a})};N(v.prototype,{cache:{get:function(){return this[y]}},credentials:{get:function(){return this[z]}},headers:{get:function(){return this[p]}},integrity:{get:function(){return this[A]}},
method:{get:function(){return this[x]}},mode:{get:function(){return this[m]}},redirect:{get:function(){return this[F]}},url:{get:function(){return this[w]}}});P.call(v.prototype);P.call(q.prototype);q.prototype.clone=function(){var a=null;null!==this[n]&&(a=T(this[n],!0),this[n]=a[0],a=a[1]);return new q(a,{status:this[r],statusText:this[I],headers:D(this[p],J),url:this[w]})};N(q.prototype,{headers:{get:function(){return this[p]}},ok:{get:function(){return this[S]}},status:{get:function(){return this[r]}},
statusText:{get:function(){return this[I]}},type:{get:function(){return this[H]}},url:{get:function(){return this[w]}}});q.error=function(){var a=new q(null);a[p][u]=U;a[H]="error";a[r]=0;a[I]="";return a};q.redirect=function(a,b){if(!FetchInternal.isUrlValid(a,!0))throw new d("Invalid URL for response redirect");void 0===b&&(b=302);if(-1===ra.indexOf(b))throw new R("Invalid status code for response redirect");return new q(null,{status:b,headers:{location:a}})};e.Headers=h;e.Request=v;e.Response=
q;e.fetch=function(a,b){return new E(function(c,f){var e=!1,g=!1,h=new v(a,b),k=new XMLHttpRequest,l=null,n=new M({start:function(a){l=a},cancel:function(a){e=!0;k.abort()}});k.onload=function(){l.close()};k.onreadystatechange=function(){if(k.readyState===k.HEADERS_RECEIVED){var a={status:k.status,statusText:k.statusText,headers:oa(k.getAllResponseHeaders()||"",J)};a.url="responseURL"in k?k.responseURL:a.headers.get("X-Request-URL");try{var b=new q(n,a);b[H]=g?"cors":"basic";c(b)}catch(ta){f(ta)}}};
k.onerror=function(){l.error(new d("Network request failed"));f(new d("Network request failed"))};k.ontimeout=function(){l.error(new d("Network request failed"));f(new d("Network request failed"))};k.open(h.method,h.url,!0);"include"===h.credentials&&(k.withCredentials=!0);h.headers.forEach(function(a,b){k.setRequestHeader(b,a)});var m=function(a){e||l.enqueue(a)},p=function(a){g=a};null===h.body?k.fetch(m,p,null):K(h).then(function(a){k.fetch(m,p,a)})})};e.fetch.polyfill=!0}})(this);