define(["require","exports","tslib","../../deps/bluebird_fork"],function(e,t,r,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),s=r.__importDefault(s);n.register=function(e){var t=this;e.factories.push(function(e){return e===t.type?t:void 0})},n.create=function(e,t){return e instanceof this?e.new():new this(this,t)},n.prototype.tryConclude=function(e){var t,r=this.xhr;r.readyState===r.DONE&&(this.response.status=r.status,this.response.message=r.statusText,this.response.headers=function(e){var t={};if("string"!=typeof e)return t;for(var r=0,s=e.split(/\r?\n/);r<s.length;r++){var n,i=s[r],o=i.indexOf(":");0<=o&&(n=i.substr(0,o).trim(),i=i.substr(o+1).trim(),(o=t[n])instanceof Array?o.push(i):t[n]="string"==typeof o?[o,i]:i)}return t}(r.getAllResponseHeaders()),("string"==typeof(t=r.response)||t instanceof ArrayBuffer)&&(this.response.content=t),this.resolver.resolve(200<=r.status&&r.status<300)),null!=e&&(this.response.error=e,this.resolver.resolve(!1))},n.prototype.cancel=function(){this.resolver.resolve(!1)},n.prototype.send=function(){var t=this,e=this.promise;if(void 0===e){if((e=this.promise=this.resolver.promise.timeout(this.timeout).catch(function(e){return!1})).isResolved())return e;var r=this.xhr=new XMLHttpRequest;e.finally(function(){return r.abort()});try{r.open(this.request.method||"GET",this.request.url,!0),r.onreadystatechange=function(e){return t.tryConclude()},r.onerror=function(e){return t.tryConclude(e.error)},this.corsWithCredentials&&(r.withCredentials=!0),this.binary?r.responseType="arraybuffer":r.responseType="text";var s,n=this.request.headers;for(s in n){var i=n[s];if(i instanceof Array)for(var o=0,u=i;o<u.length;o++){var a=u[o];r.setRequestHeader(s,"string"==typeof a?a:JSON.stringify(a))}else r.setRequestHeader(s,"string"==typeof i?i:JSON.stringify(i))}var h=this.request.json,f=void 0!==h?JSON.stringify(h):this.request.content;r.send(f)}catch(e){this.response.error=e,this.resolver.resolve(!1)}}return e},n.prototype.getResponseData=function(e){return e},n.prototype.new=function(){return new this.type(this.type,this.name)},n.type="59378113-D159-4E5C-A4AB-292F6E52620E:ChannelProvider",r=n;function n(e,t){this.resolver=s.default.defer(),this.binary=!1,this.timeout=6e4,this.corsWithCredentials=!1,this.name=t,this.type=e,this.request={headers:{}},this.response={headers:{}}}t.ChannelProvider=r});