blob: 9fcb75fa48381a730cda6cf3d9ce012412ff61d6 [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 P(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 V(a,b){throw new d("Immutable header cannot be modified");}function W(a,b){return!1}function X(a,b){a=a.toLowerCase();return-1<Y.indexOf(a)||a.startsWith("proxy-")||a.startsWith("sec-")?!0:!1}function Z(a,b){a=a.toLowerCase();return-1<aa.indexOf(a)||"content-type"===a&&(b=b.split(";")[0].toLowerCase(),-1<ba.indexOf(b))?!1:!0}function I(a,b){return-1<ca.indexOf(a.toLowerCase())?!0:!1}function h(a){this[l]=new F;
void 0===this[t]&&(this[t]=W);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=da(h.prototype);c[t]=b;h.call(c,a);return c}function J(a){if(a.bodyUsed)return K(new d("Body was already read"));
if(null===a.body)return ea(new u(0));if(fa(a.body))return K(new d("ReadableStream was already locked"));var b=a.body.getReader(),c=[],f=0;return b.read().then(function ha(a){if(a.done){if(0===c.length)a=new u(0);else if(1===c.length)a=new u(c[0]);else{a=new u(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 u?(f+=a.value.length,c.push(a.value),b.read().then(ha)):K(new d("Invalid stream data type"))})}function Q(){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(R.prototype.isPrototypeOf(a))b.enqueue(new u(a));else if(ia(a))b.enqueue(new u(a.buffer));else throw new d("Unsupported BodyInit type");b.close()}});this[r].get("content-type")||"string"===typeof a&&this[r].set("content-type","text/plain;charset=UTF-8")};N(this,{body:{get:function(){return this[n]}},bodyUsed:{get:function(){return this[L]?!0:this[n]?
!!ja(this[n]):!1}}});this.arrayBuffer=function(){return J(this).then(function(a){return a.buffer})};this.text=function(){return J(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[E]=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===ka.indexOf(this[y]))throw new d("Invalid request cache mode");this[z]=
b.credentials||this[z]||"omit";if(-1===la.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===ma.indexOf(a))throw new d("Invalid request method");this[x]=a;if(b.mode&&-1===na.indexOf(b.mode))throw new d("Invalid request mode");this[m]=b.mode||this[m]||"no-cors";if("no-cors"===this[m]){if(-1===oa.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[E]=b.redirect||this[E]||"follow";if(-1===pa.indexOf(this[E]))throw new d("Invalid request redirect mode");this[r]="no-cors"===this[m]?D(e,Z):D(e,X);if(("GET"===this[x]||"HEAD"===this[x])&&f)throw new d("Request body is not allowed for GET or HEAD");this._initBody(f)}function qa(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[G]="default";this[p]="status"in b?b.status:200;if(200>this[p]||599<this[p])throw new S("Invalid response status");this[T]=200<=this[p]&&300>this[p];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[H]=c;this[r]=D(b.headers,I);this[w]=b.url||"";if(a&&-1<ra.indexOf(this[p]))throw new d("Response body is not allowed with a null body status");this._initBody(a)}if(!e.fetch){var C=e.Array,R=e.ArrayBuffer,da=e.Object.create,N=e.Object.defineProperties,g=e.Symbol,sa=g.iterator,F=e.Map,S=e.RangeError,d=e.TypeError,u=e.Uint8Array,O=e.Promise,K=O.reject,ea=O.resolve,M=e.ReadableStream,U=e.ReadableStreamTee,ja=e.IsReadableStreamDisturbed,fa=e.IsReadableStreamLocked,n=g("body"),L=g("bodyUsed"),
y=g("cache"),z=g("credentials"),t=g("guardCallback"),r=g("headers"),A=g("integrity"),l=g("map"),x=g("method"),m=g("mode"),T=g("ok"),E=g("redirect"),p=g("status"),H=g("statusText"),G=g("type"),w=g("url"),Y="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(" "),ca=["set-cookie","set-cookie2"],aa=["accept","accept-language",
"content-language"],ba=["application/x-www-form-urlencoded","multipart/form-data","text/plain"],ka="default no-store reload no-cache force-cache only-if-cached".split(" "),la=["omit","same-origin","include"],ma="DELETE GET HEAD OPTIONS POST PUT".split(" "),oa=["GET","HEAD","POST"],na=["same-origin","no-cors","cors"],pa=["follow","error","manual"],ra=[101,204,205,304],ta=[301,302,303,307,308],ua="[object Int8Array];[object Uint8Array];[object Uint8ClampedArray];[object Int16Array];[object Uint16Array];[object Int32Array];[object Uint32Array];[object Float32Array];[object Float64Array]".split(";"),
ia=R.isView||function(a){return a&&-1<ua.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=P(b);this[t](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[t](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=P(b);this[t](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 F(C.from(this[l].entries()).sort())).keys()};
h.prototype.values=function(){return(new F(C.from(this[l].entries()).sort())).values()};h.prototype.entries=function(){return(new F(C.from(this[l].entries()).sort())).entries()};h.prototype[sa]=h.prototype.entries;v.prototype.clone=function(){var a=null;null!==this[n]&&(a=U(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[r]}},integrity:{get:function(){return this[A]}},
method:{get:function(){return this[x]}},mode:{get:function(){return this[m]}},redirect:{get:function(){return this[E]}},url:{get:function(){return this[w]}}});Q.call(v.prototype);Q.call(q.prototype);q.prototype.clone=function(){var a=null;null!==this[n]&&(a=U(this[n],!0),this[n]=a[0],a=a[1]);return new q(a,{status:this[p],statusText:this[H],headers:D(this[r],I),url:this[w]})};N(q.prototype,{headers:{get:function(){return this[r]}},ok:{get:function(){return this[T]}},status:{get:function(){return this[p]}},
statusText:{get:function(){return this[H]}},type:{get:function(){return this[G]}},url:{get:function(){return this[w]}}});q.error=function(){var a=new q(null);a[r][t]=V;a[G]="error";a[p]=0;a[H]="";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===ta.indexOf(b))throw new S("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 O(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:qa(k.getAllResponseHeaders()||"",I)};a.url="responseURL"in k?k.responseURL:a.headers.get("X-Request-URL");try{var b=new q(n,a);b[G]=g?"cors":"basic";c(b)}catch(va){f(va)}}};
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):J(h).then(function(a){k.fetch(m,p,a)})})};e.fetch.polyfill=!0}})(this);