Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- > http = require("http");
- { _connectionListener: [Function: connectionListener],
- 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' ],
- STATUS_CODES:
- { '100': 'Continue',
- '101': 'Switching Protocols',
- '102': 'Processing',
- '103': 'Early Hints',
- '200': 'OK',
- '201': 'Created',
- '202': 'Accepted',
- '203': 'Non-Authoritative Information',
- '204': 'No Content',
- '205': 'Reset Content',
- '206': 'Partial Content',
- '207': 'Multi-Status',
- '208': 'Already Reported',
- '226': 'IM Used',
- '300': 'Multiple Choices',
- '301': 'Moved Permanently',
- '302': 'Found',
- '303': 'See Other',
- '304': 'Not Modified',
- '305': 'Use Proxy',
- '307': 'Temporary Redirect',
- '308': 'Permanent 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 Timeout',
- '409': 'Conflict',
- '410': 'Gone',
- '411': 'Length Required',
- '412': 'Precondition Failed',
- '413': 'Payload Too Large',
- '414': 'URI Too Long',
- '415': 'Unsupported Media Type',
- '416': 'Range Not Satisfiable',
- '417': 'Expectation Failed',
- '418': 'I\'m a Teapot',
- '421': 'Misdirected Request',
- '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',
- '451': 'Unavailable For Legal Reasons',
- '500': 'Internal Server Error',
- '501': 'Not Implemented',
- '502': 'Bad Gateway',
- '503': 'Service Unavailable',
- '504': 'Gateway Timeout',
- '505': 'HTTP Version Not Supported',
- '506': 'Variant Also Negotiates',
- '507': 'Insufficient Storage',
- '508': 'Loop Detected',
- '509': 'Bandwidth Limit Exceeded',
- '510': 'Not Extended',
- '511': 'Network Authentication Required' },
- Agent:
- { [Function: Agent]
- super_:
- { [Function: EventEmitter]
- EventEmitter: [Circular],
- usingDomains: true,
- defaultMaxListeners: [Getter/Setter],
- init: [Function],
- listenerCount: [Function] },
- defaultMaxSockets: Infinity },
- ClientRequest:
- { [Function: ClientRequest] super_: { [Function: OutgoingMessage] super_: [Function] } },
- globalAgent:
- Agent {
- domain:
- Domain {
- domain: null,
- _events: [Object],
- _eventsCount: 3,
- _maxListeners: undefined,
- members: [] },
- _events: [Object: null prototype] { free: [Function] },
- _eventsCount: 1,
- _maxListeners: undefined,
- defaultPort: 80,
- protocol: 'http:',
- options: { path: null },
- requests: {},
- sockets: {},
- freeSockets: {},
- keepAliveMsecs: 1000,
- keepAlive: false,
- maxSockets: Infinity,
- maxFreeSockets: 256 },
- IncomingMessage:
- { [Function: IncomingMessage]
- super_:
- { [Function: Readable]
- ReadableState: [Function: ReadableState],
- super_: [Function],
- _fromList: [Function: fromList] } },
- OutgoingMessage:
- { [Function: OutgoingMessage]
- super_:
- { [Function: Stream]
- super_: [Function],
- Readable: [Function],
- Writable: [Function],
- Duplex: [Function],
- Transform: [Function],
- PassThrough: [Function],
- pipeline: [Function: pipeline],
- finished: [Function: eos],
- Stream: [Circular],
- _isUint8Array: [Function: isUint8Array],
- _uint8ArrayToBuffer: [Function: _uint8ArrayToBuffer] } },
- Server:
- { [Function: Server] super_: { [Function: Server] super_: [Function] } },
- ServerResponse:
- { [Function: ServerResponse] super_: { [Function: OutgoingMessage] super_: [Function] } },
- createServer: [Function: createServer],
- get: [Function: get],
- request: [Function: request],
- maxHeaderSize: [Getter] }
- > for(h in http){console.log(h + " : " + http[h]);}
- _connectionListener : function connectionListener(socket) {
- defaultTriggerAsyncIdScope(
- getOrSetAsyncId(socket), connectionListenerInternal, this, socket
- );
- }
- 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
- STATUS_CODES : [object Object]
- Agent : function Agent(options) {
- if (!(this instanceof Agent))
- return new Agent(options);
- EventEmitter.call(this);
- this.defaultPort = 80;
- this.protocol = 'http:';
- this.options = util._extend({}, options);
- // don't confuse net and make it think that we're connecting to a pipe
- this.options.path = null;
- this.requests = {};
- this.sockets = {};
- this.freeSockets = {};
- this.keepAliveMsecs = this.options.keepAliveMsecs || 1000;
- this.keepAlive = this.options.keepAlive || false;
- this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets;
- this.maxFreeSockets = this.options.maxFreeSockets || 256;
- this.on('free', (socket, options) => {
- var name = this.getName(options);
- debug('agent.on(free)', name);
- if (socket.writable &&
- this.requests[name] && this.requests[name].length) {
- const req = this.requests[name].shift();
- setRequestSocket(this, req, socket);
- if (this.requests[name].length === 0) {
- // don't leak
- delete this.requests[name];
- }
- } else {
- // If there are no pending requests, then put it in
- // the freeSockets pool, but only if we're allowed to do so.
- var req = socket._httpMessage;
- if (req &&
- req.shouldKeepAlive &&
- socket.writable &&
- this.keepAlive) {
- var freeSockets = this.freeSockets[name];
- var freeLen = freeSockets ? freeSockets.length : 0;
- var count = freeLen;
- if (this.sockets[name])
- count += this.sockets[name].length;
- if (count > this.maxSockets || freeLen >= this.maxFreeSockets) {
- socket.destroy();
- } else if (this.keepSocketAlive(socket)) {
- freeSockets = freeSockets || [];
- this.freeSockets[name] = freeSockets;
- socket[async_id_symbol] = -1;
- socket._httpMessage = null;
- this.removeSocket(socket, options);
- freeSockets.push(socket);
- } else {
- // Implementation doesn't want to keep socket alive
- socket.destroy();
- }
- } else {
- socket.destroy();
- }
- }
- });
- }
- ClientRequest : function ClientRequest(input, options, cb) {
- OutgoingMessage.call(this);
- if (typeof input === 'string') {
- input = url.parse(input);
- if (!input.hostname) {
- throw new ERR_INVALID_DOMAIN_NAME();
- }
- } else if (input && input[searchParamsSymbol] &&
- input[searchParamsSymbol][searchParamsSymbol]) {
- // url.URL instance
- input = urlToOptions(input);
- } else {
- cb = options;
- options = input;
- input = null;
- }
- if (typeof options === 'function') {
- cb = options;
- options = null;
- }
- options = util._extend(input || {}, options || {});
- var agent = options.agent;
- var defaultAgent = options._defaultAgent || Agent.globalAgent;
- if (agent === false) {
- agent = new defaultAgent.constructor();
- } else if (agent === null || agent === undefined) {
- if (typeof options.createConnection !== 'function') {
- agent = defaultAgent;
- }
- // Explicitly pass through this statement as agent will not be used
- // when createConnection is provided.
- } else if (typeof agent.addRequest !== 'function') {
- throw new ERR_INVALID_ARG_TYPE('options.agent',
- ['Agent-like Object', 'undefined', 'false'],
- agent);
- }
- this.agent = agent;
- var protocol = options.protocol || defaultAgent.protocol;
- var expectedProtocol = defaultAgent.protocol;
- if (this.agent && this.agent.protocol)
- expectedProtocol = this.agent.protocol;
- var path;
- if (options.path) {
- path = String(options.path);
- if (INVALID_PATH_REGEX.test(path))
- throw new ERR_UNESCAPED_CHARACTERS('Request path');
- }
- if (protocol !== expectedProtocol) {
- throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
- }
- var defaultPort = options.defaultPort ||
- this.agent && this.agent.defaultPort;
- var port = options.port = options.port || defaultPort || 80;
- var host = options.host = validateHost(options.hostname, 'hostname') ||
- validateHost(options.host, 'host') || 'localhost';
- var setHost = (options.setHost === undefined || Boolean(options.setHost));
- this.socketPath = options.socketPath;
- this.timeout = options.timeout;
- var method = options.method;
- var methodIsString = (typeof method === 'string');
- if (method !== null && method !== undefined && !methodIsString) {
- throw new ERR_INVALID_ARG_TYPE('method', 'string', method);
- }
- if (methodIsString && method) {
- if (!checkIsHttpToken(method)) {
- throw new ERR_INVALID_HTTP_TOKEN('Method', method);
- }
- method = this.method = method.toUpperCase();
- } else {
- method = this.method = 'GET';
- }
- this.path = options.path || '/';
- if (cb) {
- this.once('response', cb);
- }
- if (method === 'GET' ||
- method === 'HEAD' ||
- method === 'DELETE' ||
- method === 'OPTIONS' ||
- method === 'CONNECT') {
- this.useChunkedEncodingByDefault = false;
- } else {
- this.useChunkedEncodingByDefault = true;
- }
- this._ended = false;
- this.res = null;
- this.aborted = undefined;
- this.timeoutCb = null;
- this.upgradeOrConnect = false;
- this.parser = null;
- this.maxHeadersCount = null;
- var called = false;
- if (this.agent) {
- // If there is an agent we should default to Connection:keep-alive,
- // but only if the Agent will actually reuse the connection!
- // If it's not a keepAlive agent, and the maxSockets==Infinity, then
- // there's never a case where this socket will actually be reused
- if (!this.agent.keepAlive && !Number.isFinite(this.agent.maxSockets)) {
- this._last = true;
- this.shouldKeepAlive = false;
- } else {
- this._last = false;
- this.shouldKeepAlive = true;
- }
- }
- var headersArray = Array.isArray(options.headers);
- if (!headersArray) {
- if (options.headers) {
- var keys = Object.keys(options.headers);
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
- this.setHeader(key, options.headers[key]);
- }
- }
- if (host && !this.getHeader('host') && setHost) {
- var hostHeader = host;
- // For the Host header, ensure that IPv6 addresses are enclosed
- // in square brackets, as defined by URI formatting
- // https://tools.ietf.org/html/rfc3986#section-3.2.2
- var posColon = hostHeader.indexOf(':');
- if (posColon !== -1 &&
- hostHeader.indexOf(':', posColon + 1) !== -1 &&
- hostHeader.charCodeAt(0) !== 91/* '[' */) {
- hostHeader = `[${hostHeader}]`;
- }
- if (port && +port !== defaultPort) {
- hostHeader += ':' + port;
- }
- this.setHeader('Host', hostHeader);
- }
- if (options.auth && !this.getHeader('Authorization')) {
- this.setHeader('Authorization', 'Basic ' +
- Buffer.from(options.auth).toString('base64'));
- }
- if (this.getHeader('expect')) {
- if (this._header) {
- throw new ERR_HTTP_HEADERS_SENT('render');
- }
- this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
- this[outHeadersKey]);
- }
- } else {
- this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
- options.headers);
- }
- var oncreate = (err, socket) => {
- if (called)
- return;
- called = true;
- if (err) {
- process.nextTick(() => this.emit('error', err));
- return;
- }
- this.onSocket(socket);
- this._deferToConnect(null, null, () => this._flush());
- };
- // initiate connection
- if (this.agent) {
- this.agent.addRequest(this, options);
- } else {
- // No agent, default to Connection:close.
- this._last = true;
- this.shouldKeepAlive = false;
- if (typeof options.createConnection === 'function') {
- const newSocket = options.createConnection(options, oncreate);
- if (newSocket && !called) {
- called = true;
- this.onSocket(newSocket);
- } else {
- return;
- }
- } else {
- debug('CLIENT use net.createConnection', options);
- this.onSocket(net.createConnection(options));
- }
- }
- this._deferToConnect(null, null, () => this._flush());
- }
- globalAgent : [object Object]
- IncomingMessage : function IncomingMessage(socket) {
- Stream.Readable.call(this);
- this._readableState.readingMore = true;
- this.socket = socket;
- this.connection = socket;
- this.httpVersionMajor = null;
- this.httpVersionMinor = null;
- this.httpVersion = null;
- this.complete = false;
- this.headers = {};
- this.rawHeaders = [];
- this.trailers = {};
- this.rawTrailers = [];
- this.readable = true;
- this.aborted = false;
- this.upgrade = null;
- // request (server) only
- this.url = '';
- this.method = null;
- // response (client) only
- this.statusCode = null;
- this.statusMessage = null;
- this.client = socket;
- this._consuming = false;
- // flag for when we decide that this message cannot possibly be
- // read by the user, so there's no point continuing to handle it.
- this._dumped = false;
- }
- OutgoingMessage : function OutgoingMessage() {
- Stream.call(this);
- // Queue that holds all currently pending data, until the response will be
- // assigned to the socket (until it will its turn in the HTTP pipeline).
- this.output = [];
- this.outputEncodings = [];
- this.outputCallbacks = [];
- // `outputSize` is an approximate measure of how much data is queued on this
- // response. `_onPendingData` will be invoked to update similar global
- // per-connection counter. That counter will be used to pause/unpause the
- // TCP socket and HTTP Parser and thus handle the backpressure.
- this.outputSize = 0;
- this.writable = true;
- this._last = false;
- this.chunkedEncoding = false;
- this.shouldKeepAlive = true;
- this.useChunkedEncodingByDefault = true;
- this.sendDate = false;
- this._removedConnection = false;
- this._removedContLen = false;
- this._removedTE = false;
- this._contentLength = null;
- this._hasBody = true;
- this._trailer = '';
- this.finished = false;
- this._headerSent = false;
- this[kIsCorked] = false;
- this.socket = null;
- this.connection = null;
- this._header = null;
- this[outHeadersKey] = null;
- this._onPendingData = noopPendingOutput;
- }
- Server : function Server(options, requestListener) {
- if (!(this instanceof Server)) return new Server(options, requestListener);
- if (typeof options === 'function') {
- requestListener = options;
- options = {};
- } else if (options == null || typeof options === 'object') {
- options = util._extend({}, options);
- }
- this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
- this[kServerResponse] = options.ServerResponse || ServerResponse;
- net.Server.call(this, { allowHalfOpen: true });
- if (requestListener) {
- this.on('request', requestListener);
- }
- // Similar option to this. Too lazy to write my own docs.
- // http://www.squid-cache.org/Doc/config/half_closed_clients/
- // http://wiki.squid-cache.org/SquidFaq/InnerWorkings#What_is_a_half-closed_filedescriptor.3F
- this.httpAllowHalfOpen = false;
- this.on('connection', connectionListener);
- this.timeout = 2 * 60 * 1000;
- this.keepAliveTimeout = 5000;
- this._pendingResponseData = 0;
- this.maxHeadersCount = null;
- this.headersTimeout = 40 * 1000; // 40 seconds
- }
- ServerResponse : function ServerResponse(req) {
- OutgoingMessage.call(this);
- if (req.method === 'HEAD') this._hasBody = false;
- this.sendDate = true;
- this._sent100 = false;
- this._expect_continue = false;
- if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
- this.useChunkedEncodingByDefault = chunkExpression.test(req.headers.te);
- this.shouldKeepAlive = false;
- }
- }
- createServer : function createServer(opts, requestListener) {
- return new Server(opts, requestListener);
- }
- get : function get(url, options, cb) {
- var req = request(url, options, cb);
- req.end();
- return req;
- }
- request : function request(url, options, cb) {
- return new ClientRequest(url, options, cb);
- }
- maxHeaderSize : 8192
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement