/*
	Copyright (c) 2004-2016, The JS Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/

//>>built
define("dojo/request/node","require ./util ./handlers ../errors/RequestTimeoutError ../node!http ../node!https ../node!url ../node!stream".split(" "),function(y,g,p,q,r,t,u,v){function l(d,a){var b=g.parseArgs(d,g.deepCreate(w,a),a&&a.data instanceof x);d=b.url;a=b.options;var e=g.deferred(b,function(f,k){k.clientRequest.abort()});d=u.parse(d);var c=b.requestOptions={hostname:d.hostname,port:d.port,socketPath:a.socketPath,method:a.method,headers:a.headers,agent:a.agent,pfx:a.pfx,key:a.key,passphrase:a.passphrase,
cert:a.cert,ca:a.ca,ciphers:a.ciphers,rejectUnauthorized:!1===a.rejectUnauthorized?!1:!0};d.path&&(c.path=d.path);if(a.user||a.password)c.auth=(a.user||"")+":"+(a.password||"");c=b.clientRequest=("https:"===d.protocol?t:r).request(c);if(a.socketOptions&&("timeout"in a.socketOptions&&c.setTimeout(a.socketOptions.timeout),"noDelay"in a.socketOptions&&c.setNoDelay(a.socketOptions.noDelay),"keepAlive"in a.socketOptions)){var m=a.socketOptions.keepAlive;c.setKeepAlive(0<=m,m||0)}c.on("socket",function(){b.hasSocket=
!0;e.progress(b)});c.on("response",function(f){b.clientResponse=f;b.status=f.statusCode;b.getHeader=function(h){return f.headers[h.toLowerCase()]||null};var k=[];f.on("data",function(h){k.push(h)});f.on("end",function(){n&&clearTimeout(n);b.text=k.join("");g.checkStatus(b.status)||e.reject({message:"http response code "+b.status,response:b});try{p(b),e.resolve(b)}catch(h){e.reject(h)}})});c.on("error",e.reject);a.data?"string"===typeof a.data?c.end(a.data):a.data.pipe(c):c.end();if(a.timeout)var n=
setTimeout(function(){e.cancel(new q(b))},a.timeout);return e.promise}var x=v.Stream,w={method:"GET",query:null,data:void 0,headers:{}};g.addCommonMethods(l);return l});