Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. > http = require("http");
  2. { _connectionListener: [Function: connectionListener],
  3.   METHODS:
  4.    [ 'ACL',
  5.      'BIND',
  6.      'CHECKOUT',
  7.      'CONNECT',
  8.      'COPY',
  9.      'DELETE',
  10.      'GET',
  11.      'HEAD',
  12.      'LINK',
  13.      'LOCK',
  14.      'M-SEARCH',
  15.      'MERGE',
  16.      'MKACTIVITY',
  17.      'MKCALENDAR',
  18.      'MKCOL',
  19.      'MOVE',
  20.      'NOTIFY',
  21.      'OPTIONS',
  22.      'PATCH',
  23.      'POST',
  24.      'PROPFIND',
  25.      'PROPPATCH',
  26.      'PURGE',
  27.      'PUT',
  28.      'REBIND',
  29.      'REPORT',
  30.      'SEARCH',
  31.      'SOURCE',
  32.      'SUBSCRIBE',
  33.      'TRACE',
  34.      'UNBIND',
  35.      'UNLINK',
  36.      'UNLOCK',
  37.      'UNSUBSCRIBE' ],
  38.   STATUS_CODES:
  39.    { '100': 'Continue',
  40.      '101': 'Switching Protocols',
  41.      '102': 'Processing',
  42.      '103': 'Early Hints',
  43.      '200': 'OK',
  44.      '201': 'Created',
  45.      '202': 'Accepted',
  46.      '203': 'Non-Authoritative Information',
  47.      '204': 'No Content',
  48.      '205': 'Reset Content',
  49.      '206': 'Partial Content',
  50.      '207': 'Multi-Status',
  51.      '208': 'Already Reported',
  52.      '226': 'IM Used',
  53.      '300': 'Multiple Choices',
  54.      '301': 'Moved Permanently',
  55.      '302': 'Found',
  56.      '303': 'See Other',
  57.      '304': 'Not Modified',
  58.      '305': 'Use Proxy',
  59.      '307': 'Temporary Redirect',
  60.      '308': 'Permanent Redirect',
  61.      '400': 'Bad Request',
  62.      '401': 'Unauthorized',
  63.      '402': 'Payment Required',
  64.      '403': 'Forbidden',
  65.      '404': 'Not Found',
  66.      '405': 'Method Not Allowed',
  67.      '406': 'Not Acceptable',
  68.      '407': 'Proxy Authentication Required',
  69.      '408': 'Request Timeout',
  70.      '409': 'Conflict',
  71.      '410': 'Gone',
  72.      '411': 'Length Required',
  73.      '412': 'Precondition Failed',
  74.      '413': 'Payload Too Large',
  75.      '414': 'URI Too Long',
  76.      '415': 'Unsupported Media Type',
  77.      '416': 'Range Not Satisfiable',
  78.      '417': 'Expectation Failed',
  79.      '418': 'I\'m a Teapot',
  80.      '421': 'Misdirected Request',
  81.      '422': 'Unprocessable Entity',
  82.      '423': 'Locked',
  83.      '424': 'Failed Dependency',
  84.      '425': 'Unordered Collection',
  85.      '426': 'Upgrade Required',
  86.      '428': 'Precondition Required',
  87.      '429': 'Too Many Requests',
  88.      '431': 'Request Header Fields Too Large',
  89.      '451': 'Unavailable For Legal Reasons',
  90.      '500': 'Internal Server Error',
  91.      '501': 'Not Implemented',
  92.      '502': 'Bad Gateway',
  93.      '503': 'Service Unavailable',
  94.      '504': 'Gateway Timeout',
  95.      '505': 'HTTP Version Not Supported',
  96.      '506': 'Variant Also Negotiates',
  97.      '507': 'Insufficient Storage',
  98.      '508': 'Loop Detected',
  99.      '509': 'Bandwidth Limit Exceeded',
  100.      '510': 'Not Extended',
  101.      '511': 'Network Authentication Required' },
  102.   Agent:
  103.    { [Function: Agent]
  104.      super_:
  105.       { [Function: EventEmitter]
  106.         EventEmitter: [Circular],
  107.         usingDomains: true,
  108.         defaultMaxListeners: [Getter/Setter],
  109.         init: [Function],
  110.         listenerCount: [Function] },
  111.      defaultMaxSockets: Infinity },
  112.   ClientRequest:
  113.    { [Function: ClientRequest] super_: { [Function: OutgoingMessage] super_: [Function] } },
  114.   globalAgent:
  115.    Agent {
  116.      domain:
  117.       Domain {
  118.         domain: null,
  119.         _events: [Object],
  120.         _eventsCount: 3,
  121.         _maxListeners: undefined,
  122.         members: [] },
  123.      _events: [Object: null prototype] { free: [Function] },
  124.      _eventsCount: 1,
  125.      _maxListeners: undefined,
  126.      defaultPort: 80,
  127.      protocol: 'http:',
  128.      options: { path: null },
  129.      requests: {},
  130.      sockets: {},
  131.      freeSockets: {},
  132.      keepAliveMsecs: 1000,
  133.      keepAlive: false,
  134.      maxSockets: Infinity,
  135.      maxFreeSockets: 256 },
  136.   IncomingMessage:
  137.    { [Function: IncomingMessage]
  138.      super_:
  139.       { [Function: Readable]
  140.         ReadableState: [Function: ReadableState],
  141.         super_: [Function],
  142.         _fromList: [Function: fromList] } },
  143.   OutgoingMessage:
  144.    { [Function: OutgoingMessage]
  145.      super_:
  146.       { [Function: Stream]
  147.         super_: [Function],
  148.         Readable: [Function],
  149.         Writable: [Function],
  150.         Duplex: [Function],
  151.         Transform: [Function],
  152.         PassThrough: [Function],
  153.         pipeline: [Function: pipeline],
  154.         finished: [Function: eos],
  155.         Stream: [Circular],
  156.         _isUint8Array: [Function: isUint8Array],
  157.         _uint8ArrayToBuffer: [Function: _uint8ArrayToBuffer] } },
  158.   Server:
  159.    { [Function: Server] super_: { [Function: Server] super_: [Function] } },
  160.   ServerResponse:
  161.    { [Function: ServerResponse] super_: { [Function: OutgoingMessage] super_: [Function] } },
  162.   createServer: [Function: createServer],
  163.   get: [Function: get],
  164.   request: [Function: request],
  165.   maxHeaderSize: [Getter] }
  166. > for(h in http){console.log(h + " : " + http[h]);}
  167. _connectionListener : function connectionListener(socket) {
  168.   defaultTriggerAsyncIdScope(
  169.     getOrSetAsyncId(socket), connectionListenerInternal, this, socket
  170.   );
  171. }
  172. METHODS : ACL,BIND,CHECKOUT,CONNECT,COPY,DELETE,GET,HEAD,LINK,LOCK,M-SEARCH,MERGE,MKACTIVITY,MKCALENDAR,MKCOL,MOVE,NOTIFY,OPTIONS,PATCH,POST,PROPFIND,PROPPATCH,PURGE,PUT,REBIND,REPORT,SEARCH,SOURCE,SUBSCRIBE,TRACE,UNBIND,UNLINK,UNLOCK,UNSUBSCRIBE
  173. STATUS_CODES : [object Object]
  174. Agent : function Agent(options) {
  175.   if (!(this instanceof Agent))
  176.     return new Agent(options);
  177.  
  178.   EventEmitter.call(this);
  179.  
  180.   this.defaultPort = 80;
  181.   this.protocol = 'http:';
  182.  
  183.   this.options = util._extend({}, options);
  184.  
  185.   // don't confuse net and make it think that we're connecting to a pipe
  186.   this.options.path = null;
  187.   this.requests = {};
  188.   this.sockets = {};
  189.   this.freeSockets = {};
  190.   this.keepAliveMsecs = this.options.keepAliveMsecs || 1000;
  191.   this.keepAlive = this.options.keepAlive || false;
  192.   this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets;
  193.   this.maxFreeSockets = this.options.maxFreeSockets || 256;
  194.  
  195.   this.on('free', (socket, options) => {
  196.     var name = this.getName(options);
  197.     debug('agent.on(free)', name);
  198.  
  199.     if (socket.writable &&
  200.         this.requests[name] && this.requests[name].length) {
  201.       const req = this.requests[name].shift();
  202.       setRequestSocket(this, req, socket);
  203.       if (this.requests[name].length === 0) {
  204.         // don't leak
  205.         delete this.requests[name];
  206.       }
  207.     } else {
  208.       // If there are no pending requests, then put it in
  209.       // the freeSockets pool, but only if we're allowed to do so.
  210.       var req = socket._httpMessage;
  211.       if (req &&
  212.           req.shouldKeepAlive &&
  213.           socket.writable &&
  214.           this.keepAlive) {
  215.         var freeSockets = this.freeSockets[name];
  216.         var freeLen = freeSockets ? freeSockets.length : 0;
  217.         var count = freeLen;
  218.         if (this.sockets[name])
  219.           count += this.sockets[name].length;
  220.  
  221.         if (count > this.maxSockets || freeLen >= this.maxFreeSockets) {
  222.           socket.destroy();
  223.         } else if (this.keepSocketAlive(socket)) {
  224.           freeSockets = freeSockets || [];
  225.           this.freeSockets[name] = freeSockets;
  226.           socket[async_id_symbol] = -1;
  227.           socket._httpMessage = null;
  228.           this.removeSocket(socket, options);
  229.           freeSockets.push(socket);
  230.         } else {
  231.           // Implementation doesn't want to keep socket alive
  232.           socket.destroy();
  233.         }
  234.       } else {
  235.         socket.destroy();
  236.       }
  237.     }
  238.   });
  239. }
  240. ClientRequest : function ClientRequest(input, options, cb) {
  241.   OutgoingMessage.call(this);
  242.  
  243.   if (typeof input === 'string') {
  244.     input = url.parse(input);
  245.     if (!input.hostname) {
  246.       throw new ERR_INVALID_DOMAIN_NAME();
  247.     }
  248.   } else if (input && input[searchParamsSymbol] &&
  249.              input[searchParamsSymbol][searchParamsSymbol]) {
  250.     // url.URL instance
  251.     input = urlToOptions(input);
  252.   } else {
  253.     cb = options;
  254.     options = input;
  255.     input = null;
  256.   }
  257.  
  258.   if (typeof options === 'function') {
  259.     cb = options;
  260.     options = null;
  261.   }
  262.  
  263.   options = util._extend(input || {}, options || {});
  264.  
  265.   var agent = options.agent;
  266.   var defaultAgent = options._defaultAgent || Agent.globalAgent;
  267.   if (agent === false) {
  268.     agent = new defaultAgent.constructor();
  269.   } else if (agent === null || agent === undefined) {
  270.     if (typeof options.createConnection !== 'function') {
  271.       agent = defaultAgent;
  272.     }
  273.     // Explicitly pass through this statement as agent will not be used
  274.     // when createConnection is provided.
  275.   } else if (typeof agent.addRequest !== 'function') {
  276.     throw new ERR_INVALID_ARG_TYPE('options.agent',
  277.                                    ['Agent-like Object', 'undefined', 'false'],
  278.                                    agent);
  279.   }
  280.   this.agent = agent;
  281.  
  282.   var protocol = options.protocol || defaultAgent.protocol;
  283.   var expectedProtocol = defaultAgent.protocol;
  284.   if (this.agent && this.agent.protocol)
  285.     expectedProtocol = this.agent.protocol;
  286.  
  287.   var path;
  288.   if (options.path) {
  289.     path = String(options.path);
  290.     if (INVALID_PATH_REGEX.test(path))
  291.       throw new ERR_UNESCAPED_CHARACTERS('Request path');
  292.   }
  293.  
  294.   if (protocol !== expectedProtocol) {
  295.     throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
  296.   }
  297.  
  298.   var defaultPort = options.defaultPort ||
  299.                     this.agent && this.agent.defaultPort;
  300.  
  301.   var port = options.port = options.port || defaultPort || 80;
  302.   var host = options.host = validateHost(options.hostname, 'hostname') ||
  303.                             validateHost(options.host, 'host') || 'localhost';
  304.  
  305.   var setHost = (options.setHost === undefined || Boolean(options.setHost));
  306.  
  307.   this.socketPath = options.socketPath;
  308.   this.timeout = options.timeout;
  309.  
  310.   var method = options.method;
  311.   var methodIsString = (typeof method === 'string');
  312.   if (method !== null && method !== undefined && !methodIsString) {
  313.     throw new ERR_INVALID_ARG_TYPE('method', 'string', method);
  314.   }
  315.  
  316.   if (methodIsString && method) {
  317.     if (!checkIsHttpToken(method)) {
  318.       throw new ERR_INVALID_HTTP_TOKEN('Method', method);
  319.     }
  320.     method = this.method = method.toUpperCase();
  321.   } else {
  322.     method = this.method = 'GET';
  323.   }
  324.  
  325.   this.path = options.path || '/';
  326.   if (cb) {
  327.     this.once('response', cb);
  328.   }
  329.  
  330.   if (method === 'GET' ||
  331.       method === 'HEAD' ||
  332.       method === 'DELETE' ||
  333.       method === 'OPTIONS' ||
  334.       method === 'CONNECT') {
  335.     this.useChunkedEncodingByDefault = false;
  336.   } else {
  337.     this.useChunkedEncodingByDefault = true;
  338.   }
  339.  
  340.   this._ended = false;
  341.   this.res = null;
  342.   this.aborted = undefined;
  343.   this.timeoutCb = null;
  344.   this.upgradeOrConnect = false;
  345.   this.parser = null;
  346.   this.maxHeadersCount = null;
  347.  
  348.   var called = false;
  349.  
  350.   if (this.agent) {
  351.     // If there is an agent we should default to Connection:keep-alive,
  352.     // but only if the Agent will actually reuse the connection!
  353.     // If it's not a keepAlive agent, and the maxSockets==Infinity, then
  354.     // there's never a case where this socket will actually be reused
  355.     if (!this.agent.keepAlive && !Number.isFinite(this.agent.maxSockets)) {
  356.       this._last = true;
  357.       this.shouldKeepAlive = false;
  358.     } else {
  359.       this._last = false;
  360.       this.shouldKeepAlive = true;
  361.     }
  362.   }
  363.  
  364.   var headersArray = Array.isArray(options.headers);
  365.   if (!headersArray) {
  366.     if (options.headers) {
  367.       var keys = Object.keys(options.headers);
  368.       for (var i = 0; i < keys.length; i++) {
  369.         var key = keys[i];
  370.         this.setHeader(key, options.headers[key]);
  371.       }
  372.     }
  373.  
  374.     if (host && !this.getHeader('host') && setHost) {
  375.       var hostHeader = host;
  376.  
  377.       // For the Host header, ensure that IPv6 addresses are enclosed
  378.       // in square brackets, as defined by URI formatting
  379.       // https://tools.ietf.org/html/rfc3986#section-3.2.2
  380.       var posColon = hostHeader.indexOf(':');
  381.       if (posColon !== -1 &&
  382.           hostHeader.indexOf(':', posColon + 1) !== -1 &&
  383.           hostHeader.charCodeAt(0) !== 91/* '[' */) {
  384.         hostHeader = `[${hostHeader}]`;
  385.       }
  386.  
  387.       if (port && +port !== defaultPort) {
  388.         hostHeader += ':' + port;
  389.       }
  390.       this.setHeader('Host', hostHeader);
  391.     }
  392.  
  393.     if (options.auth && !this.getHeader('Authorization')) {
  394.       this.setHeader('Authorization', 'Basic ' +
  395.                      Buffer.from(options.auth).toString('base64'));
  396.     }
  397.  
  398.     if (this.getHeader('expect')) {
  399.       if (this._header) {
  400.         throw new ERR_HTTP_HEADERS_SENT('render');
  401.       }
  402.  
  403.       this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
  404.                         this[outHeadersKey]);
  405.     }
  406.   } else {
  407.     this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
  408.                       options.headers);
  409.   }
  410.  
  411.   var oncreate = (err, socket) => {
  412.     if (called)
  413.       return;
  414.     called = true;
  415.     if (err) {
  416.       process.nextTick(() => this.emit('error', err));
  417.       return;
  418.     }
  419.     this.onSocket(socket);
  420.     this._deferToConnect(null, null, () => this._flush());
  421.   };
  422.  
  423.   // initiate connection
  424.   if (this.agent) {
  425.     this.agent.addRequest(this, options);
  426.   } else {
  427.     // No agent, default to Connection:close.
  428.     this._last = true;
  429.     this.shouldKeepAlive = false;
  430.     if (typeof options.createConnection === 'function') {
  431.       const newSocket = options.createConnection(options, oncreate);
  432.       if (newSocket && !called) {
  433.         called = true;
  434.         this.onSocket(newSocket);
  435.       } else {
  436.         return;
  437.       }
  438.     } else {
  439.       debug('CLIENT use net.createConnection', options);
  440.       this.onSocket(net.createConnection(options));
  441.     }
  442.   }
  443.  
  444.   this._deferToConnect(null, null, () => this._flush());
  445. }
  446. globalAgent : [object Object]
  447. IncomingMessage : function IncomingMessage(socket) {
  448.   Stream.Readable.call(this);
  449.  
  450.   this._readableState.readingMore = true;
  451.  
  452.   this.socket = socket;
  453.   this.connection = socket;
  454.  
  455.   this.httpVersionMajor = null;
  456.   this.httpVersionMinor = null;
  457.   this.httpVersion = null;
  458.   this.complete = false;
  459.   this.headers = {};
  460.   this.rawHeaders = [];
  461.   this.trailers = {};
  462.   this.rawTrailers = [];
  463.  
  464.   this.readable = true;
  465.  
  466.   this.aborted = false;
  467.  
  468.   this.upgrade = null;
  469.  
  470.   // request (server) only
  471.   this.url = '';
  472.   this.method = null;
  473.  
  474.   // response (client) only
  475.   this.statusCode = null;
  476.   this.statusMessage = null;
  477.   this.client = socket;
  478.  
  479.   this._consuming = false;
  480.   // flag for when we decide that this message cannot possibly be
  481.   // read by the user, so there's no point continuing to handle it.
  482.   this._dumped = false;
  483. }
  484. OutgoingMessage : function OutgoingMessage() {
  485.   Stream.call(this);
  486.  
  487.   // Queue that holds all currently pending data, until the response will be
  488.   // assigned to the socket (until it will its turn in the HTTP pipeline).
  489.   this.output = [];
  490.   this.outputEncodings = [];
  491.   this.outputCallbacks = [];
  492.  
  493.   // `outputSize` is an approximate measure of how much data is queued on this
  494.   // response. `_onPendingData` will be invoked to update similar global
  495.   // per-connection counter. That counter will be used to pause/unpause the
  496.   // TCP socket and HTTP Parser and thus handle the backpressure.
  497.   this.outputSize = 0;
  498.  
  499.   this.writable = true;
  500.  
  501.   this._last = false;
  502.   this.chunkedEncoding = false;
  503.   this.shouldKeepAlive = true;
  504.   this.useChunkedEncodingByDefault = true;
  505.   this.sendDate = false;
  506.   this._removedConnection = false;
  507.   this._removedContLen = false;
  508.   this._removedTE = false;
  509.  
  510.   this._contentLength = null;
  511.   this._hasBody = true;
  512.   this._trailer = '';
  513.  
  514.   this.finished = false;
  515.   this._headerSent = false;
  516.   this[kIsCorked] = false;
  517.  
  518.   this.socket = null;
  519.   this.connection = null;
  520.   this._header = null;
  521.   this[outHeadersKey] = null;
  522.  
  523.   this._onPendingData = noopPendingOutput;
  524. }
  525. Server : function Server(options, requestListener) {
  526.   if (!(this instanceof Server)) return new Server(options, requestListener);
  527.  
  528.   if (typeof options === 'function') {
  529.     requestListener = options;
  530.     options = {};
  531.   } else if (options == null || typeof options === 'object') {
  532.     options = util._extend({}, options);
  533.   }
  534.  
  535.   this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
  536.   this[kServerResponse] = options.ServerResponse || ServerResponse;
  537.  
  538.   net.Server.call(this, { allowHalfOpen: true });
  539.  
  540.   if (requestListener) {
  541.     this.on('request', requestListener);
  542.   }
  543.  
  544.   // Similar option to this. Too lazy to write my own docs.
  545.   // http://www.squid-cache.org/Doc/config/half_closed_clients/
  546.   // http://wiki.squid-cache.org/SquidFaq/InnerWorkings#What_is_a_half-closed_filedescriptor.3F
  547.   this.httpAllowHalfOpen = false;
  548.  
  549.   this.on('connection', connectionListener);
  550.  
  551.   this.timeout = 2 * 60 * 1000;
  552.   this.keepAliveTimeout = 5000;
  553.   this._pendingResponseData = 0;
  554.   this.maxHeadersCount = null;
  555.   this.headersTimeout = 40 * 1000; // 40 seconds
  556. }
  557. ServerResponse : function ServerResponse(req) {
  558.   OutgoingMessage.call(this);
  559.  
  560.   if (req.method === 'HEAD') this._hasBody = false;
  561.  
  562.   this.sendDate = true;
  563.   this._sent100 = false;
  564.   this._expect_continue = false;
  565.  
  566.   if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
  567.     this.useChunkedEncodingByDefault = chunkExpression.test(req.headers.te);
  568.     this.shouldKeepAlive = false;
  569.   }
  570. }
  571. createServer : function createServer(opts, requestListener) {
  572.   return new Server(opts, requestListener);
  573. }
  574. get : function get(url, options, cb) {
  575.   var req = request(url, options, cb);
  576.   req.end();
  577.   return req;
  578. }
  579. request : function request(url, options, cb) {
  580.   return new ClientRequest(url, options, cb);
  581. }
  582. maxHeaderSize : 8192
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement