Skip to content

Commit

Permalink
typings: add JSDoc typings for http
Browse files Browse the repository at this point in the history
PR-URL: #38191
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
VoltrexKeyva authored and targos committed Apr 16, 2021
1 parent fc20e83 commit d3162da
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,65 @@ const {
} = require('_http_server');
let maxHeaderSize;

/**
* Returns a new instance of `http.Server`.
* @param {{
* IncomingMessage?: IncomingMessage;
* ServerResponse?: ServerResponse;
* insecureHTTPParser?: boolean;
* maxHeaderSize?: number;
* }} [opts]
* @param {Function} [requestListener]
* @returns {Server}
*/
function createServer(opts, requestListener) {
return new Server(opts, requestListener);
}

/**
* @typedef {Object} HTTPRequestOptions
* @property {httpAgent.Agent | boolean} [agent]
* @property {string} [auth]
* @property {Function} [createConnection]
* @property {number} [defaultPort]
* @property {number} [family]
* @property {Object} [headers]
* @property {number} [hints]
* @property {string} [host]
* @property {string} [hostname]
* @property {boolean} [insecureHTTPParser]
* @property {string} [localAddress]
* @property {number} [localPort]
* @property {Function} [lookup]
* @property {number} [maxHeaderSize]
* @property {string} [method]
* @property {string} [path]
* @property {number} [port]
* @property {string} [protocol]
* @property {boolean} [setHost]
* @property {string} [socketPath]
* @property {number} [timeout]
* @property {AbortSignal} [signal]
*/

/**
* Makes an HTTP request.
* @param {string | URL} url
* @param {HTTPRequestOptions} [options]
* @param {Function} [cb]
* @returns {ClientRequest}
*/
function request(url, options, cb) {
return new ClientRequest(url, options, cb);
}

/**
* Makes a `GET` HTTP request.
* @param {string | URL} url
* @param {HTTPRequestOptions} [options]
* @param {Function} [cb]
* @returns {ClientRequest}
*/
function get(url, options, cb) {
const req = request(url, options, cb);
req.end();
Expand Down

0 comments on commit d3162da

Please sign in to comment.