define(["Ti/_","Ti/_/declare","Ti/_/has","Ti/_/lang","Ti/_/Evented","Ti/Filesystem","Ti/Network","Ti/Blob","Ti/_/event","Ti/App"],function(t,e,s,i,r,n,o,a,h,u){var d=require.is,c=require.on;return e("Ti.Network.HTTPClient",r,{constructor:function(){var t=this._xhr=new XMLHttpRequest;this._handles=[c(t,"error",this,"_onError"),t.upload&&c(t.upload,"error",this,"_onError"),c(t,"progress",this,function(t){t.progress=t.lengthComputable?t.loaded/t.total:!1,d(this.ondatastream,"Function")&&this.ondatastream.call(this,t)}),t.upload&&c(t.upload,"progress",this,function(t){t.progress=t.lengthComputable?t.loaded/t.total:!1,d(this.onsendstream,"Function")&&this.onsendstream.call(this,t)})],t.onreadystatechange=i.hitch(this,function(){var e,i=this.__values__.constants,r=this.onload;switch(t.readyState){case 0:i.readyState=this.UNSENT;break;case 1:i.readyState=this.OPENED;break;case 2:i.readyState=this.LOADING;break;case 3:i.readyState=this.HEADERS_RECEIVED;break;case 4:clearTimeout(this._timeoutTimer),this._completed=1,i.readyState=this.DONE,this._aborted||((e=this.file)&&(e=n.getFile(e),e.writable&&e.write(t.responseText)),i.responseText=t.responseText,i.responseData=new a({data:t.responseText,length:t.responseText.length,mimeType:t.getResponseHeader("Content-Type")||"text/plain"}),i.responseXML=t.responseXML,s("ti-instrumentation")&&instrumentation.stopTest(this._requestInstrumentationTest,this.location),t.status>=400&&(r=this._onError),d(r,"Function")&&r.call(this))}this._fireStateChange()})},destroy:function(){this._xhr&&(this._xhr.abort(),this._xhr=null),h.off(this._handles),r.destroy.apply(this,arguments)},_onError:function(t){this.abort(),d(t,"Object")||(t={message:t}),t.source=this,t.type="error",t.error||(t.error=t.message||this._xhr.status),parseInt(t.error)||(t.error="Can't reach host"),d(this.onerror,"Function")&&this.onerror.call(this,t)},abort:function(){clearTimeout(this._timeoutTimer),this._aborted=1,this.connected&&this._xhr.abort(),this.__values__.constants.readyState=this.UNSENT,this._fireStateChange()},_fireStateChange:function(){d(this.onreadystatechange,"Function")&&this.onreadystatechange.call(this)},getResponseHeader:function(t){return this._xhr.readyState>1?this._xhr.getResponseHeader(t):null},open:function(e,s,i){var r=Ti.Network.httpURLFormatter,n=this.__values__.constants,o=this.withCredentials,a=t.getAbsolutePath(r?r(s):s),h=a.match(/^((?:.+\:)?\/\/)?(?:.+@)?(.*)$/);h&&this.username&&this.password&&(a=(h[1]||"")+(this.domain?this.domain+"\\":"")+this.username+":"+this.password+"@"+h[2]),this.abort(),this._xhr.open(n.connectionType=e,n.location=a,o||void 0===i?!0:!!i),o&&(this._xhr.withCredentials=o)},send:function(t){try{var e=0|this.timeout;this._aborted=this._completed=0,s("ti-instrumentation")&&(this._requestInstrumentationTest=instrumentation.startTest("HTTP Request")),t=d(t,"Object")?i.urlEncode(t):t,this._contentTypeSet||t&&this._xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),this._xhr.setRequestHeader("X-Titanium-Id",u.guid),this._xhr.send(t),clearTimeout(this._timeoutTimer),e&&(this._timeoutTimer=setTimeout(i.hitch(this,function(){this.connected&&(this.abort(),!this._completed&&this._onError("Request timed out"))}),e))}catch(r){}},setRequestHeader:function(t,e){"Content-Type"===t&&(this._contentTypeSet=1),this._xhr.setRequestHeader(t,e)},properties:{ondatastream:void 0,onerror:void 0,onload:void 0,onreadystatechange:void 0,onsendstream:void 0,timeout:void 0,username:null,password:null,domain:null,withCredentials:!1},constants:{DONE:4,HEADERS_RECEIVED:2,LOADING:3,OPENED:1,UNSENT:1,connected:function(){return this.readyState>=this.OPENED},connectionType:void 0,location:void 0,readyState:this.UNSENT,responseData:void 0,responseText:void 0,responseXML:void 0,status:function(){return this._xhr.status},statusText:function(){return this._xhr.statusText}}})});