// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/utils/requests/UniversalClient","dojo/_base/declare dojo/_base/lang dojo/_base/url dojo/Deferred dojo/request/xhr dojo/io-query dojo/sniff dojo/when esri/kernel esri/config esri/lang esri/urlUtils ../UrlUtil ./BinaryData ./FileContent ./MultipartDataBuilder ./ErrorUtil".split(" "),function(w,r,H,t,x,y,z,I,n,u,A,v,p,B,C,D,q){function E(a,c){if(c)this.reject(c);else{var b=a.xhr,d=b.getResponseHeader&&b.getResponseHeader("Content-Type");a.status=b.status;a.data=new B(b.response||
b.responseBody||b.responseText,d);this.resolve(a)}}var F=0,G=z("safari"),l=w(null,{constructor:function(a){"string"===typeof a?this.url=a:"object"===typeof a&&r.mixin(this,a)},url:null,preventCache:null,usePost:!1,timeout:0,multipartThreshold:0,useCommonAuth:!1,useProxy:!1,allowSSL:null,send:function(a,c){return this.sendUrlRequest(this.prepareUrlRequest(a,c),"UniversalClient.send")},prepareUrlRequest:function(a,c){"string"===typeof a?a={urlSuffix:a}:a||(a={});c||(c={});var b=a.url||this.url,d=a.urlSuffix;
b||(b=d,d=null);if(!b)throw Error("URL is missing.");var e=v.urlToObject(b),b=p.combine(e.path,d),d=e.query||{};"object"===typeof c.content&&(d=r.mixin(d,c.content));e=c.requireSSL;!0!==e&&!1===this.allowSSL&&(e=!1);!1!==e&&!0===this.allowSSL&&/^https/i.test(window.location.protocol)&&(e=!0);if(n.id){var f=n.id.findCredential(b);!f&&this.useCommonAuth&&(f="string"==typeof this.useCommonAuth?n.id.findCredential(this.useCommonAuth):n.id.credentials[0]);f&&(d.token||!1===d.token||(d.token=f.token),f.ssl&&
!1!==e&&(e=!0))}!0===e&&(b=p.toHttpsUrl(b));!1===d.token&&delete d.token;var k=c.handleAs||"json";"json"===k&&(d.f="json");var f=(c.sendAs||(c.usePost||this.usePost||d.token?"post":"get")).toLowerCase(),e="multipart"==f?!0:c.sendAs||c.sizeLimit?!1:null,l=0,g;for(g in d){var m=d[g];m instanceof C?e=!0:("object"==typeof m&&(m=d[g]=JSON.stringify(m)),!e&&0<this.multipartThreshold&&(l+=g.length+(m?m.length:0)+2))}!1!==e&&0<this.multipartThreshold&&l>this.multipartThreshold&&(e=!0);if(c.useProxy||!v.hasSameOrigin(b,
window.location.href)&&this.useProxy&&!c.hasOwnProperty("useProxy")){var h=p.getProxyUrl();h&&(b=h+"?"+b)}g=(g=c.hasOwnProperty("preventCache")?c.preventCache:this.preventCache)||null===g&&h||G?"_ts\x3d"+(new Date).getTime()+F++:"";h={handleAs:k};if(k=Number(A.isDefined(c.timeout)?c.timeout:this.timeout))h.timeout=k;k="get"!=f||e;f=e?null:y.objectToQuery(d);k||(k=f.length+b.length+g.length+1>=u.defaults.io.postLength);h.method=k?"POST":"GET";h.headers={"X-Requested-With":null};h.headers["Content-Type"]=
"undefined"!=typeof c.contentType?c.contentType:"application/x-www-form-urlencoded; charset\x3dutf-8";e?(e=new D,e.addVariables(d),e.build(h)):k?h.data=f:f&&(b+="?"+f,g&&(b+="\x26"+g),g=null);!f&&g&&(b+="?"+g);return{url:b,options:h,sizeLimit:c.sizeLimit}},sendUrlRequest:function(a,c){var b="string"===typeof a.options.data?a.options.data.length:null;if(a.sizeLimit&&b&&("function"===typeof a.sizeLimit?a.sizeLimit(b):b>a.sizeLimit))return(new t).reject(Error("SIZE_LIMIT_EXCEEDED"));c=c||"UniversalClient.sendUrlRequest";
var d=a.deferred||new t;if(b="bin"==a.options.handleAs)a.options.handleAs="blob";var e=x(a.url,a.options,!0);b&&(e.handleResponse=E);var f=this;e.then(function(b){b="json"==a.options.handleAs&&b&&q.parseError(b)||b;b instanceof Error?(498===b.code&&l.handleInvalidTokenError(b),d.reject(b)):d.resolve(f._makeResponse(c,b))},function(a){d.reject(q.makeError(a))});return d.promise},requestToUrl:function(a){if(a.options.headers&&a.options.headers["Content-Type"]&&0==a.options.headers["Content-Type"].indexOf("multipart/form-data"))return null;
var c=a.url;if(a=a.options.data){if(c.length+a.length>=u.defaults.io.postLength)return null;c+="?"+a}return c},_makeResponse:function(a,c){return c}});l.makeError=q.makeError;l.handleInvalidTokenError=function(a){};return l});