%PDF- %PDF-
Direktori : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/httpserver/lib/ |
Current File : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/httpserver/lib/httpserver.js |
function readStart(n){n&&n._handle&&n._handle.readStart&&(n._drain_paused||n._handle.readStart())}function readStop(n){n&&n._handle&&n._handle.readStop&&n._handle.readStop()}function parserOnHeaders(n,t){(this.maxHeaderPairs<=0||this._headers.length<this.maxHeaderPairs)&&(this._headers=this._headers.concat(n));this._url+=t}function parserOnHeadersComplete(n){var t=this,i=n.headers,f=n.url,u,r,o,s,e;for(i||(i=t._headers,t._headers=[]),f||(f=t._url,t._url=""),t.incoming=new IncomingMessage(t.socket),t.incoming.httpVersionMajor=n.versionMajor,t.incoming.httpVersionMinor=n.versionMinor,t.incoming.httpVersion=n.versionMajor+"."+n.versionMinor,t.incoming.url=f,u=i.length,t.maxHeaderPairs>0&&(u=Math.min(u,t.maxHeaderPairs)),r=0;r<u;r+=2)o=i[r],s=i[r+1],t.incoming._addHeaderLine(o,s);return n.method?t.incoming.method=n.method:t.incoming.statusCode=n.statusCode,t.incoming.upgrade=n.upgrade,e=!1,n.upgrade||(e=t.onIncoming(t.incoming,n.shouldKeepAlive)),e}function parserOnBody(n,t,i){var o=this,r=o.incoming,u,f,e;r&&(u=r.socket,i>0&&!r._dumped&&(f=n.slice(t,t+i),e=r.push(f),e||readStop(u)))}function parserOnMessageComplete(){var n=this,t=n.incoming,i,r,u,f,e;if(t){if(t.complete=!0,i=n._headers,i){for(r=0,u=i.length;r<u;r+=2)f=i[r],e=i[r+1],n.incoming._addHeaderLine(f,e);n._headers=[];n._url=""}t.upgrade||t.push(null)}t&&!n.incoming._pendings.length&&t.push(null);n.socket.readable&&readStart(n.socket)}function utcDate(){if(!dateCache){var n=new Date;dateCache=n.toUTCString();setTimeout(function(){dateCache=undefined},1e3-n.getMilliseconds())}return dateCache}function IncomingMessage(n){Stream.Readable.call(this);this.socket=n;this.connection=n;this.httpVersion=null;this.complete=!1;this.headers={};this.trailers={};this.readable=!0;this._pendings=[];this._pendingIndex=0;this.url="";this.method=null;this.statusCode=null;this.client=this.socket;this._consuming=!1;this._dumped=!1}function OutgoingMessage(){Stream.call(this);this.output=[];this.outputEncodings=[];this.writable=!0;this._last=!1;this.chunkedEncoding=!1;this.shouldKeepAlive=!0;this.useChunkedEncodingByDefault=!0;this.sendDate=!1;this._hasBody=!0;this._trailer="";this.finished=!1;this._hangupClose=!1;this.socket=null;this.connection=null}function storeHeader(n,t,i,r){/[\r\n]/.test(r)&&(r=r.replace(/[\r\n]+[ \t]*/g,""));t.messageHeader+=i+": "+r+CRLF;connectionExpression.test(i)?(t.sentConnectionHeader=!0,closeExpression.test(r)?n._last=!0:n.shouldKeepAlive=!0):transferEncodingExpression.test(i)?(t.sentTransferEncodingHeader=!0,chunkExpression.test(r)&&(n.chunkedEncoding=!0)):contentLengthExpression.test(i)?t.sentContentLengthHeader=!0:dateExpression.test(i)?t.sentDateHeader=!0:expectExpression.test(i)?t.sentExpect=!0:(cacheControlExpression.test(i)||expiresExpression.test(i))&&(t.sentCacheHeader=!0)}function ServerResponse(n){OutgoingMessage.call(this);n.method==="HEAD"&&(this._hasBody=!1);this.sendDate=!0;(n.httpVersionMajor<1||n.httpVersionMinor<1)&&(this.useChunkedEncodingByDefault=chunkExpression.test(n.headers.te),this.shouldKeepAlive=!1)}function onServerResponseClose(){this._httpMessage&&this._httpMessage.emit("close")}function ondrain(){this._httpMessage&&this._httpMessage.emit("drain")}function httpSocketSetup(n){n.removeListener("drain",ondrain);n.on("drain",ondrain)}function Server(n){if(!(this instanceof Server))return new Server(n);EventEmitter.call(this);n&&this.addListener("request",n);this.httpAllowHalfOpen=!1;this.addListener("connection",connectionListener);this.addListener("clientError",function(n,t){t.destroy(n)});this.timeout=12e4}function connectionListener(n){function f(){while(r.length){var n=r.shift();n.emit("aborted");n.emit("close")}}function e(n,t){n&&(n._headers=[],n.onIncoming=null,n.socket&&(n.socket.onend=null,n.socket.ondata=null,n.socket.parser=null),n.socket=null,n.incoming=null,parsers.free(n),n=null);t&&(t.parser=null)}function o(){debug("server socket close");this.parser&&e(this.parser);f();dssUtils.gcNextTick()}function s(){n._drain_paused&&(n._drain_paused=!1,n.parser.resume(),n.resume())}var i=this,u=[],r=[],t;debug("SERVER new http connection");httpSocketSetup(n);i.timeout&&n.setTimeout(i.timeout);n.on("timeout",function(){var t=n.parser&&n.parser.incoming,u=t&&!t.complete&&t.emit("timeout",n),r=n._httpMessage,f=r&&r.emit("timeout",n),e=i.emit("timeout",n);u||f||e||n.destroy()});t=parsers.alloc();t.reinitialize(HTTPParser.REQUEST);t.socket=n;n.parser=t;t.incoming=null;t.maxHeaderPairs=typeof this.maxHeadersCount=="number"?this.maxHeadersCount<<1:2e3;n.addListener("error",function(n){i.emit("clientError",n,this)});n.ondata=function(r,u,f){var h,l,s,a,c;assert(!n._drain_paused);h=t.execute(r,u,f-u);h instanceof Error?(debug("parse error"),n.destroy(h)):t.incoming&&t.incoming.upgrade&&(l=h,s=t.incoming,n.ondata=null,n.onend=null,n.removeListener("close",o),t.finish(),e(t,s),a=r.slice(u+l,f),c=s.method==="CONNECT"?"connect":"upgrade",EventEmitter.listenerCount(i,c)>0?(n.unshift(a),i.emit(c,s,s.socket,emptyBuffer)):n.destroy(),n._drain_paused&&(debug("pause parser"),n.parser.pause()))};n.onend=function(){var r=t.finish();if(r instanceof Error){debug("parse error");n.destroy(r);return}i.httpAllowHalfOpen?u.length?u[u.length-1]._last=!0:n._httpMessage?n._httpMessage._last=!0:n.writable&&n.end():(f(),n.writable&&n.end())};n.addListener("close",o);n._drain_paused=!1;n.on("drain",s);t.onIncoming=function(t,f){var o,e;r.push(t);!n._drain_paused&&n._handle&&(o=n._handle.writeQueueSize>0,o&&(n._drain_paused=!0,n.pause()));e=new ServerResponse(t);e.shouldKeepAlive=f;DTRACE_HTTP_SERVER_REQUEST(t,n);COUNTER_HTTP_SERVER_REQUEST();n._httpMessage?u.push(e):e.assignSocket(n);e.on("finish",function(){if(assert(r.length==0||r[0]===t),r.shift(),t._consuming||t._dump(),e.detachSocket(n),e._last)n.destroySoon();else{var i=u.shift();i&&i.assignSocket(n)}});return t.headers.expect!==undefined&&t.httpVersionMajor==1&&t.httpVersionMinor==1&&continueExpression.test(t.headers.expect)?(e._expect_continue=!0,EventEmitter.listenerCount(i,"checkContinue")>0?i.emit("checkContinue",t,e):(e.writeContinue(),i.emit("request",t,e))):i.emit("request",t,e),!1}}var util=require("util"),Stream=require("stream"),url=require("url"),EventEmitter=require("events").EventEmitter,FreeList=require("freelist").FreeList,HTTPParser=process.binding("http_parser").HTTPParser,assert=require("assert").ok,dssUtils=require("dss-utils"),emptyBuffer=new Buffer(0),debug,parsers,zero_chunk_buf,crlf_buf;debug=process.env.NODE_DEBUG&&/http/.test(process.env.NODE_DEBUG)?function(n){console.error("HTTP: %s",n)}:function(){};parsers=new FreeList("parsers",1e3,function(){var n=new HTTPParser(HTTPParser.REQUEST);return n._headers=[],n._url="",n.onHeaders=parserOnHeaders,n.onHeadersComplete=parserOnHeadersComplete,n.onBody=parserOnBody,n.onMessageComplete=parserOnMessageComplete,n});exports.parsers=parsers;var CRLF="\r\n",STATUS_CODES=exports.STATUS_CODES={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Time-out",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Request Entity Too Large",414:"Request-URI Too Large",415:"Unsupported Media Type",416:"Requested Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Unordered Collection",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"},connectionExpression=/Connection/i,transferEncodingExpression=/Transfer-Encoding/i,closeExpression=/close/i,chunkExpression=/chunk/i,contentLengthExpression=/Content-Length/i,dateExpression=/Date/i,cacheControlExpression=/Cache-Control/i,expiresExpression=/Expires/i,expectExpression=/Expect/i,continueExpression=/100-continue/i,dateCache;util.inherits(IncomingMessage,Stream.Readable);exports.IncomingMessage=IncomingMessage;IncomingMessage.prototype.setTimeout=function(n,t){if(t)this.on("timeout",t);this.socket.setTimeout(n)};IncomingMessage.prototype.read=function(n){return this._consuming=!0,this.read=Stream.Readable.prototype.read,this.read(n)};IncomingMessage.prototype._read=function(){this.socket.readable?readStart(this.socket):this.push(null)};IncomingMessage.prototype.destroy=function(n){this.socket&&this.socket.destroy(n)};IncomingMessage.prototype._addHeaderLine=function(n,t){var i=this.complete?this.trailers:this.headers;n=n.toLowerCase();switch(n){case"set-cookie":i[n]!==undefined?i[n].push(t):i[n]=[t];break;case"accept":case"accept-charset":case"accept-encoding":case"accept-language":case"connection":case"cookie":case"pragma":case"link":case"www-authenticate":case"proxy-authenticate":case"sec-websocket-extensions":case"sec-websocket-protocol":i[n]!==undefined?i[n]+=", "+t:i[n]=t;break;default:n.slice(0,2)=="x-"?i[n]!==undefined?i[n]+=", "+t:i[n]=t:i[n]===undefined&&(i[n]=t)}};IncomingMessage.prototype._dump=function(){this._dumped||(this._dumped=!0,this.socket.parser&&(this.socket.parser.incoming=null),this.push(null),readStart(this.socket),this.read())};util.inherits(OutgoingMessage,Stream);exports.OutgoingMessage=OutgoingMessage;OutgoingMessage.prototype.setTimeout=function(n,t){if(t)this.on("timeout",t);if(this.socket)this.socket.setTimeout(n);else this.once("socket",function(t){t.setTimeout(n)})};OutgoingMessage.prototype.destroy=function(n){if(this.socket)this.socket.destroy(n);else this.once("socket",function(t){t.destroy(n)})};OutgoingMessage.prototype._send=function(n,t){return this._headerSent||(typeof n=="string"?n=this._header+n:(this.output.unshift(this._header),this.outputEncodings.unshift("ascii")),this._headerSent=!0),this._writeRaw(n,t)};OutgoingMessage.prototype._writeRaw=function(n,t){if(n.length===0)return!0;if(this.connection&&this.connection._httpMessage===this&&this.connection.writable&&!this.connection.destroyed){while(this.output.length){if(!this.connection.writable)return this._buffer(n,t),!1;var i=this.output.shift(),r=this.outputEncodings.shift();this.connection.write(i,r)}return this.connection.write(n,t)}return this.connection&&this.connection.destroyed?!1:(this._buffer(n,t),!1)};OutgoingMessage.prototype._buffer=function(n,t){var i,u,r;if(n.length!==0)return(i=this.output.length,i===0||typeof n!="string")?(this.output.push(n),this.outputEncodings.push(t),!1):(u=this.outputEncodings[i-1],r=this.output[i-1],t&&u===t||!t&&n.constructor===r.constructor)?(this.output[i-1]=r+n,!1):(this.output.push(n),this.outputEncodings.push(t),!1)};OutgoingMessage.prototype._storeHeader=function(n,t){var i={sentConnectionHeader:!1,sentContentLengthHeader:!1,sentTransferEncodingHeader:!1,sentDateHeader:!1,sentExpect:!1,sentCacheHeader:!1,messageHeader:n},v=this,h,c,f,r,e,l,u,o,s,a;if(t)for(h=Object.keys(t),c=Array.isArray(t),e=0,l=h.length;e<l;e++)if(u=h[e],c?(f=t[u][0],r=t[u][1]):(f=u,r=t[u]),Array.isArray(r))for(o=0;o<r.length;o++)storeHeader(this,i,f,r[o]);else storeHeader(this,i,f,r);this.sendDate===!0&&i.sentDateHeader===!1&&(i.messageHeader+="Date: "+utcDate()+CRLF);i.sentCacheHeader===!1&&(i.messageHeader+="Cache-Control: no-cache, no-store, private"+CRLF);s=this.statusCode;(s===204||s===304)&&this.chunkedEncoding===!0&&(debug(s+" response should not use chunked encoding, closing connection."),this.chunkedEncoding=!1,this.shouldKeepAlive=!1);i.sentConnectionHeader===!1&&(a=this.shouldKeepAlive&&(i.sentContentLengthHeader||this.useChunkedEncodingByDefault||this.agent),a?i.messageHeader+="Connection: keep-alive\r\n":(this._last=!0,i.messageHeader+="Connection: close\r\n"));i.sentContentLengthHeader===!1&&i.sentTransferEncodingHeader===!1&&(this._hasBody?this.useChunkedEncodingByDefault?(i.messageHeader+="Transfer-Encoding: chunked\r\n",this.chunkedEncoding=!0):this._last=!0:this.chunkedEncoding=!1);this._header=i.messageHeader+CRLF;this._headerSent=!1;i.sentExpect&&this._send("")};OutgoingMessage.prototype.setHeader=function(n,t){if(arguments.length<2)throw new Error("`name` and `value` are required for setHeader().");if(this._header)throw new Error("Can't set headers after they are sent.");var i=n.toLowerCase();this._headers=this._headers||{};this._headerNames=this._headerNames||{};this._headers[i]=t;this._headerNames[i]=n};OutgoingMessage.prototype.getHeader=function(n){if(arguments.length<1)throw new Error("`name` is required for getHeader().");if(this._headers){var t=n.toLowerCase();return this._headers[t]}};OutgoingMessage.prototype.removeHeader=function(n){if(arguments.length<1)throw new Error("`name` is required for removeHeader().");if(this._header)throw new Error("Can't remove headers after they are sent.");if(this._headers){var t=n.toLowerCase();delete this._headers[t];delete this._headerNames[t]}};OutgoingMessage.prototype._renderHeaders=function(){var t,i,n,u,r;if(this._header)throw new Error("Can't render headers after they are sent to the client.");if(!this._headers)return{};for(t={},i=Object.keys(this._headers),n=0,u=i.length;n<u;n++)r=i[n],t[this._headerNames[r]]=this._headers[r];return t};Object.defineProperty(OutgoingMessage.prototype,"headersSent",{configurable:!0,enumerable:!0,get:function(){return!!this._header}});OutgoingMessage.prototype.write=function(n,t){if(this._header||this._implicitHeader(),!this._hasBody)return debug("This type of response MUST NOT have a body. Ignoring write() calls."),!0;if(typeof n!="string"&&!Buffer.isBuffer(n))throw new TypeError("first argument must be a string or Buffer");if(n.length===0)return!0;n instanceof Buffer&&(this.chunkedEncoding||!this._headerSent)&&(n=n.toString("binary"),t="binary");var r,i;return this.chunkedEncoding?typeof n=="string"&&t!=="hex"&&t!=="base64"?(r=Buffer.byteLength(n,t),n=r.toString(16)+CRLF+n+CRLF,i=this._send(n,t)):(r=n.length,this._send(r.toString(16)+CRLF),this._send(n,t),i=this._send(CRLF)):i=this._send(n,t),debug("write ret = "+i),i};OutgoingMessage.prototype.addTrailers=function(n){var r,e,u,f,i,o,t;for(this._trailer="",r=Object.keys(n),e=Array.isArray(n),i=0,o=r.length;i<o;i++)t=r[i],e?(u=n[t][0],f=n[t][1]):(u=t,f=n[t]),this._trailer+=u+": "+f+CRLF};zero_chunk_buf=new Buffer("\r\n0\r\n");crlf_buf=new Buffer("\r\n");OutgoingMessage.prototype.end=function(n,t){var u,e,h,f,r;if(this.finished)return!1;if(this._header||this._implicitHeader(),n&&!this._hasBody&&(debug("This type of response MUST NOT have a body. Ignoring data passed to end()."),n=!1),e=this._headerSent===!1&&n&&n.length>0&&this.output.length===0&&this.connection&&this.connection.writable&&this.connection._httpMessage===this,e&&Buffer.isBuffer(n)&&n.length>122880&&(e=!1),e){if(typeof n=="string")this.chunkedEncoding?(h=Buffer.byteLength(n,t).toString(16),u=this.connection.write(this._header+h+CRLF+n+"\r\n0\r\n"+this._trailer+"\r\n",t)):u=this.connection.write(this._header+n,t);else if(Buffer.isBuffer(n))if(this.chunkedEncoding){var c=n.length.toString(16),f=this._header.length,s=c.length,l=n.length,o=this._trailer.length,a=f+s+2+l+5+o+2,r=new Buffer(a),i=0;r.write(this._header,i,f,"ascii");i+=f;r.write(c,i,s,"ascii");i+=s;crlf_buf.copy(r,i);i+=2;n.copy(r,i);i+=l;zero_chunk_buf.copy(r,i);i+=5;o>0&&(r.write(this._trailer,i,o,"ascii"),i+=o);crlf_buf.copy(r,i);u=this.connection.write(r)}else f=this._header.length,r=new Buffer(f+n.length),r.write(this._header,0,f,"ascii"),n.copy(r,f),u=this.connection.write(r);else throw new TypeError("first argument must be a string or Buffer");this._headerSent=!0}else n&&(u=this.write(n,t));return e||(u=this.chunkedEncoding?this._send("0\r\n"+this._trailer+"\r\n"):this._send("")),this.finished=!0,debug("outgoing message end."),this.output.length===0&&this.connection._httpMessage===this&&this._finish(),dssUtils.gcNextTick(),u};OutgoingMessage.prototype._finish=function(){assert(this.connection);this instanceof ServerResponse?(DTRACE_HTTP_SERVER_RESPONSE(this.connection),COUNTER_HTTP_SERVER_RESPONSE()):(assert(this instanceof ClientRequest),DTRACE_HTTP_CLIENT_REQUEST(this,this.connection),COUNTER_HTTP_CLIENT_REQUEST());this.emit("finish")};OutgoingMessage.prototype._flush=function(){var n,t,i;if(this.socket){while(this.output.length){if(!this.socket.writable)return;t=this.output.shift();i=this.outputEncodings.shift();n=this.socket.write(t,i)}this.finished?this._finish():n&&this.emit("drain")}};util.inherits(ServerResponse,OutgoingMessage);exports.ServerResponse=ServerResponse;ServerResponse.prototype.statusCode=200;ServerResponse.prototype.assignSocket=function(n){assert(!n._httpMessage);n._httpMessage=this;n.on("close",onServerResponseClose);this.socket=n;this.connection=n;this.emit("socket",n);this._flush()};ServerResponse.prototype.detachSocket=function(n){assert(n._httpMessage==this);n.removeListener("close",onServerResponseClose);n._httpMessage=null;this.socket=this.connection=null};ServerResponse.prototype.writeContinue=function(){this._writeRaw("HTTP/1.1 100 Continue"+CRLF+CRLF,"ascii");this._sent100=!0};ServerResponse.prototype._implicitHeader=function(){this.writeHead(this.statusCode)};ServerResponse.prototype.writeHead=function(n){var e,r,o,t,u,h,s,i,f,c;if(typeof arguments[1]=="string"?(e=arguments[1],o=2):(e=STATUS_CODES[n]||"unknown",o=1),this.statusCode=n,t=arguments[o],t&&this._headers)if(r=this._renderHeaders(),Array.isArray(t)){for(i=0,h=t.length;i<h;++i)u=t[i][0],r[u]!==undefined&&t.push([u,r[u]]);r=t}else for(s=Object.keys(t),i=0;i<s.length;i++)f=s[i],f&&(r[f]=t[f]);else r=this._headers?this._renderHeaders():t;c="HTTP/1.1 "+n.toString()+" "+e+CRLF;(n===204||n===304||100<=n&&n<=199)&&(this._hasBody=!1);this._expect_continue&&!this._sent100&&(this.shouldKeepAlive=!1);this._storeHeader(c,r)};ServerResponse.prototype.writeHeader=function(){this.writeHead.apply(this,arguments)};util.inherits(Server,EventEmitter);Server.prototype.setTimeout=function(n,t){if(this.timeout=n,t)this.on("timeout",t)};Server.prototype.listen=function(){var t=this,n=arguments[arguments.length-1];if(typeof n=="function")t.once("listening",n);this.emit("listening")};Server.prototype.address=function(){return null};Server.prototype.close=function(n){if(n)this.once("close",n);this.emit("close")};exports.Server=Server;exports.createServer=function(n){return new Server(n)};exports._connectionListener=connectionListener