index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. var url = require("url");
  2. var URL = url.URL;
  3. var http = require("http");
  4. var https = require("https");
  5. var Writable = require("stream").Writable;
  6. var assert = require("assert");
  7. var debug = require("./debug");
  8. // Preventive platform detection
  9. // istanbul ignore next
  10. (function detectUnsupportedEnvironment() {
  11. var looksLikeNode = typeof process !== "undefined";
  12. var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
  13. var looksLikeV8 = isFunction(Error.captureStackTrace);
  14. if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) {
  15. console.warn("The follow-redirects package should be excluded from browser builds.");
  16. }
  17. }());
  18. // Whether to use the native URL object or the legacy url module
  19. var useNativeURL = false;
  20. try {
  21. assert(new URL(""));
  22. }
  23. catch (error) {
  24. useNativeURL = error.code === "ERR_INVALID_URL";
  25. }
  26. // HTTP headers to drop across HTTP/HTTPS and domain boundaries
  27. var sensitiveHeaders = [
  28. "Authorization",
  29. "Proxy-Authorization",
  30. "Cookie",
  31. ];
  32. // URL fields to preserve in copy operations
  33. var preservedUrlFields = [
  34. "auth",
  35. "host",
  36. "hostname",
  37. "href",
  38. "path",
  39. "pathname",
  40. "port",
  41. "protocol",
  42. "query",
  43. "search",
  44. "hash",
  45. ];
  46. // Create handlers that pass events from native requests
  47. var events = ["abort", "aborted", "connect", "error", "socket", "timeout"];
  48. var eventHandlers = Object.create(null);
  49. events.forEach(function (event) {
  50. eventHandlers[event] = function (arg1, arg2, arg3) {
  51. this._redirectable.emit(event, arg1, arg2, arg3);
  52. };
  53. });
  54. // Error types with codes
  55. var InvalidUrlError = createErrorType(
  56. "ERR_INVALID_URL",
  57. "Invalid URL",
  58. TypeError
  59. );
  60. var RedirectionError = createErrorType(
  61. "ERR_FR_REDIRECTION_FAILURE",
  62. "Redirected request failed"
  63. );
  64. var TooManyRedirectsError = createErrorType(
  65. "ERR_FR_TOO_MANY_REDIRECTS",
  66. "Maximum number of redirects exceeded",
  67. RedirectionError
  68. );
  69. var MaxBodyLengthExceededError = createErrorType(
  70. "ERR_FR_MAX_BODY_LENGTH_EXCEEDED",
  71. "Request body larger than maxBodyLength limit"
  72. );
  73. var WriteAfterEndError = createErrorType(
  74. "ERR_STREAM_WRITE_AFTER_END",
  75. "write after end"
  76. );
  77. // istanbul ignore next
  78. var destroy = Writable.prototype.destroy || noop;
  79. // An HTTP(S) request that can be redirected
  80. function RedirectableRequest(options, responseCallback) {
  81. // Initialize the request
  82. Writable.call(this);
  83. this._sanitizeOptions(options);
  84. this._options = options;
  85. this._ended = false;
  86. this._ending = false;
  87. this._redirectCount = 0;
  88. this._redirects = [];
  89. this._requestBodyLength = 0;
  90. this._requestBodyBuffers = [];
  91. // Attach a callback if passed
  92. if (responseCallback) {
  93. this.on("response", responseCallback);
  94. }
  95. // React to responses of native requests
  96. var self = this;
  97. this._onNativeResponse = function (response) {
  98. try {
  99. self._processResponse(response);
  100. }
  101. catch (cause) {
  102. self.emit("error", cause instanceof RedirectionError ?
  103. cause : new RedirectionError({ cause: cause }));
  104. }
  105. };
  106. // Create filter for sensitive HTTP headers
  107. this._headerFilter = new RegExp("^(?:" +
  108. sensitiveHeaders.concat(options.sensitiveHeaders).map(escapeRegex).join("|") +
  109. ")$", "i");
  110. // Perform the first request
  111. this._performRequest();
  112. }
  113. RedirectableRequest.prototype = Object.create(Writable.prototype);
  114. RedirectableRequest.prototype.abort = function () {
  115. destroyRequest(this._currentRequest);
  116. this._currentRequest.abort();
  117. this.emit("abort");
  118. };
  119. RedirectableRequest.prototype.destroy = function (error) {
  120. destroyRequest(this._currentRequest, error);
  121. destroy.call(this, error);
  122. return this;
  123. };
  124. // Writes buffered data to the current native request
  125. RedirectableRequest.prototype.write = function (data, encoding, callback) {
  126. // Writing is not allowed if end has been called
  127. if (this._ending) {
  128. throw new WriteAfterEndError();
  129. }
  130. // Validate input and shift parameters if necessary
  131. if (!isString(data) && !isBuffer(data)) {
  132. throw new TypeError("data should be a string, Buffer or Uint8Array");
  133. }
  134. if (isFunction(encoding)) {
  135. callback = encoding;
  136. encoding = null;
  137. }
  138. // Ignore empty buffers, since writing them doesn't invoke the callback
  139. // https://github.com/nodejs/node/issues/22066
  140. if (data.length === 0) {
  141. if (callback) {
  142. callback();
  143. }
  144. return;
  145. }
  146. // Only write when we don't exceed the maximum body length
  147. if (this._requestBodyLength + data.length <= this._options.maxBodyLength) {
  148. this._requestBodyLength += data.length;
  149. this._requestBodyBuffers.push({ data: data, encoding: encoding });
  150. this._currentRequest.write(data, encoding, callback);
  151. }
  152. // Error when we exceed the maximum body length
  153. else {
  154. this.emit("error", new MaxBodyLengthExceededError());
  155. this.abort();
  156. }
  157. };
  158. // Ends the current native request
  159. RedirectableRequest.prototype.end = function (data, encoding, callback) {
  160. // Shift parameters if necessary
  161. if (isFunction(data)) {
  162. callback = data;
  163. data = encoding = null;
  164. }
  165. else if (isFunction(encoding)) {
  166. callback = encoding;
  167. encoding = null;
  168. }
  169. // Write data if needed and end
  170. if (!data) {
  171. this._ended = this._ending = true;
  172. this._currentRequest.end(null, null, callback);
  173. }
  174. else {
  175. var self = this;
  176. var currentRequest = this._currentRequest;
  177. this.write(data, encoding, function () {
  178. self._ended = true;
  179. currentRequest.end(null, null, callback);
  180. });
  181. this._ending = true;
  182. }
  183. };
  184. // Sets a header value on the current native request
  185. RedirectableRequest.prototype.setHeader = function (name, value) {
  186. this._options.headers[name] = value;
  187. this._currentRequest.setHeader(name, value);
  188. };
  189. // Clears a header value on the current native request
  190. RedirectableRequest.prototype.removeHeader = function (name) {
  191. delete this._options.headers[name];
  192. this._currentRequest.removeHeader(name);
  193. };
  194. // Global timeout for all underlying requests
  195. RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
  196. var self = this;
  197. // Destroys the socket on timeout
  198. function destroyOnTimeout(socket) {
  199. socket.setTimeout(msecs);
  200. socket.removeListener("timeout", socket.destroy);
  201. socket.addListener("timeout", socket.destroy);
  202. }
  203. // Sets up a timer to trigger a timeout event
  204. function startTimer(socket) {
  205. if (self._timeout) {
  206. clearTimeout(self._timeout);
  207. }
  208. self._timeout = setTimeout(function () {
  209. self.emit("timeout");
  210. clearTimer();
  211. }, msecs);
  212. destroyOnTimeout(socket);
  213. }
  214. // Stops a timeout from triggering
  215. function clearTimer() {
  216. // Clear the timeout
  217. if (self._timeout) {
  218. clearTimeout(self._timeout);
  219. self._timeout = null;
  220. }
  221. // Clean up all attached listeners
  222. self.removeListener("abort", clearTimer);
  223. self.removeListener("error", clearTimer);
  224. self.removeListener("response", clearTimer);
  225. self.removeListener("close", clearTimer);
  226. if (callback) {
  227. self.removeListener("timeout", callback);
  228. }
  229. if (!self.socket) {
  230. self._currentRequest.removeListener("socket", startTimer);
  231. }
  232. }
  233. // Attach callback if passed
  234. if (callback) {
  235. this.on("timeout", callback);
  236. }
  237. // Start the timer if or when the socket is opened
  238. if (this.socket) {
  239. startTimer(this.socket);
  240. }
  241. else {
  242. this._currentRequest.once("socket", startTimer);
  243. }
  244. // Clean up on events
  245. this.on("socket", destroyOnTimeout);
  246. this.on("abort", clearTimer);
  247. this.on("error", clearTimer);
  248. this.on("response", clearTimer);
  249. this.on("close", clearTimer);
  250. return this;
  251. };
  252. // Proxy all other public ClientRequest methods
  253. [
  254. "flushHeaders", "getHeader",
  255. "setNoDelay", "setSocketKeepAlive",
  256. ].forEach(function (method) {
  257. RedirectableRequest.prototype[method] = function (a, b) {
  258. return this._currentRequest[method](a, b);
  259. };
  260. });
  261. // Proxy all public ClientRequest properties
  262. ["aborted", "connection", "socket"].forEach(function (property) {
  263. Object.defineProperty(RedirectableRequest.prototype, property, {
  264. get: function () { return this._currentRequest[property]; },
  265. });
  266. });
  267. RedirectableRequest.prototype._sanitizeOptions = function (options) {
  268. // Ensure headers are always present
  269. if (!options.headers) {
  270. options.headers = {};
  271. }
  272. if (!isArray(options.sensitiveHeaders)) {
  273. options.sensitiveHeaders = [];
  274. }
  275. // Since http.request treats host as an alias of hostname,
  276. // but the url module interprets host as hostname plus port,
  277. // eliminate the host property to avoid confusion.
  278. if (options.host) {
  279. // Use hostname if set, because it has precedence
  280. if (!options.hostname) {
  281. options.hostname = options.host;
  282. }
  283. delete options.host;
  284. }
  285. // Complete the URL object when necessary
  286. if (!options.pathname && options.path) {
  287. var searchPos = options.path.indexOf("?");
  288. if (searchPos < 0) {
  289. options.pathname = options.path;
  290. }
  291. else {
  292. options.pathname = options.path.substring(0, searchPos);
  293. options.search = options.path.substring(searchPos);
  294. }
  295. }
  296. };
  297. // Executes the next native request (initial or redirect)
  298. RedirectableRequest.prototype._performRequest = function () {
  299. // Load the native protocol
  300. var protocol = this._options.protocol;
  301. var nativeProtocol = this._options.nativeProtocols[protocol];
  302. if (!nativeProtocol) {
  303. throw new TypeError("Unsupported protocol " + protocol);
  304. }
  305. // If specified, use the agent corresponding to the protocol
  306. // (HTTP and HTTPS use different types of agents)
  307. if (this._options.agents) {
  308. var scheme = protocol.slice(0, -1);
  309. this._options.agent = this._options.agents[scheme];
  310. }
  311. // Create the native request and set up its event handlers
  312. var request = this._currentRequest =
  313. nativeProtocol.request(this._options, this._onNativeResponse);
  314. request._redirectable = this;
  315. for (var event of events) {
  316. request.on(event, eventHandlers[event]);
  317. }
  318. // RFC7230§5.3.1: When making a request directly to an origin server, […]
  319. // a client MUST send only the absolute path […] as the request-target.
  320. this._currentUrl = /^\//.test(this._options.path) ?
  321. url.format(this._options) :
  322. // When making a request to a proxy, […]
  323. // a client MUST send the target URI in absolute-form […].
  324. this._options.path;
  325. // End a redirected request
  326. // (The first request must be ended explicitly with RedirectableRequest#end)
  327. if (this._isRedirect) {
  328. // Write the request entity and end
  329. var i = 0;
  330. var self = this;
  331. var buffers = this._requestBodyBuffers;
  332. (function writeNext(error) {
  333. // Only write if this request has not been redirected yet
  334. // istanbul ignore else
  335. if (request === self._currentRequest) {
  336. // Report any write errors
  337. // istanbul ignore if
  338. if (error) {
  339. self.emit("error", error);
  340. }
  341. // Write the next buffer if there are still left
  342. else if (i < buffers.length) {
  343. var buffer = buffers[i++];
  344. // istanbul ignore else
  345. if (!request.finished) {
  346. request.write(buffer.data, buffer.encoding, writeNext);
  347. }
  348. }
  349. // End the request if `end` has been called on us
  350. else if (self._ended) {
  351. request.end();
  352. }
  353. }
  354. }());
  355. }
  356. };
  357. // Processes a response from the current native request
  358. RedirectableRequest.prototype._processResponse = function (response) {
  359. // Store the redirected response
  360. var statusCode = response.statusCode;
  361. if (this._options.trackRedirects) {
  362. this._redirects.push({
  363. url: this._currentUrl,
  364. headers: response.headers,
  365. statusCode: statusCode,
  366. });
  367. }
  368. // RFC7231§6.4: The 3xx (Redirection) class of status code indicates
  369. // that further action needs to be taken by the user agent in order to
  370. // fulfill the request. If a Location header field is provided,
  371. // the user agent MAY automatically redirect its request to the URI
  372. // referenced by the Location field value,
  373. // even if the specific status code is not understood.
  374. // If the response is not a redirect; return it as-is
  375. var location = response.headers.location;
  376. if (!location || this._options.followRedirects === false ||
  377. statusCode < 300 || statusCode >= 400) {
  378. response.responseUrl = this._currentUrl;
  379. response.redirects = this._redirects;
  380. this.emit("response", response);
  381. // Clean up
  382. this._requestBodyBuffers = [];
  383. return;
  384. }
  385. // The response is a redirect, so abort the current request
  386. destroyRequest(this._currentRequest);
  387. // Discard the remainder of the response to avoid waiting for data
  388. response.destroy();
  389. // RFC7231§6.4: A client SHOULD detect and intervene
  390. // in cyclical redirections (i.e., "infinite" redirection loops).
  391. if (++this._redirectCount > this._options.maxRedirects) {
  392. throw new TooManyRedirectsError();
  393. }
  394. // Store the request headers if applicable
  395. var requestHeaders;
  396. var beforeRedirect = this._options.beforeRedirect;
  397. if (beforeRedirect) {
  398. requestHeaders = Object.assign({
  399. // The Host header was set by nativeProtocol.request
  400. Host: response.req.getHeader("host"),
  401. }, this._options.headers);
  402. }
  403. // RFC7231§6.4: Automatic redirection needs to done with
  404. // care for methods not known to be safe, […]
  405. // RFC7231§6.4.2–3: For historical reasons, a user agent MAY change
  406. // the request method from POST to GET for the subsequent request.
  407. var method = this._options.method;
  408. if ((statusCode === 301 || statusCode === 302) && this._options.method === "POST" ||
  409. // RFC7231§6.4.4: The 303 (See Other) status code indicates that
  410. // the server is redirecting the user agent to a different resource […]
  411. // A user agent can perform a retrieval request targeting that URI
  412. // (a GET or HEAD request if using HTTP) […]
  413. (statusCode === 303) && !/^(?:GET|HEAD)$/.test(this._options.method)) {
  414. this._options.method = "GET";
  415. // Drop a possible entity and headers related to it
  416. this._requestBodyBuffers = [];
  417. removeMatchingHeaders(/^content-/i, this._options.headers);
  418. }
  419. // Drop the Host header, as the redirect might lead to a different host
  420. var currentHostHeader = removeMatchingHeaders(/^host$/i, this._options.headers);
  421. // If the redirect is relative, carry over the host of the last request
  422. var currentUrlParts = parseUrl(this._currentUrl);
  423. var currentHost = currentHostHeader || currentUrlParts.host;
  424. var currentUrl = /^\w+:/.test(location) ? this._currentUrl :
  425. url.format(Object.assign(currentUrlParts, { host: currentHost }));
  426. // Create the redirected request
  427. var redirectUrl = resolveUrl(location, currentUrl);
  428. debug("redirecting to", redirectUrl.href);
  429. this._isRedirect = true;
  430. spreadUrlObject(redirectUrl, this._options);
  431. // Drop confidential headers when redirecting to a less secure protocol
  432. // or to a different domain that is not a superdomain
  433. if (redirectUrl.protocol !== currentUrlParts.protocol &&
  434. redirectUrl.protocol !== "https:" ||
  435. redirectUrl.host !== currentHost &&
  436. !isSubdomain(redirectUrl.host, currentHost)) {
  437. removeMatchingHeaders(this._headerFilter, this._options.headers);
  438. }
  439. // Evaluate the beforeRedirect callback
  440. if (isFunction(beforeRedirect)) {
  441. var responseDetails = {
  442. headers: response.headers,
  443. statusCode: statusCode,
  444. };
  445. var requestDetails = {
  446. url: currentUrl,
  447. method: method,
  448. headers: requestHeaders,
  449. };
  450. beforeRedirect(this._options, responseDetails, requestDetails);
  451. this._sanitizeOptions(this._options);
  452. }
  453. // Perform the redirected request
  454. this._performRequest();
  455. };
  456. // Wraps the key/value object of protocols with redirect functionality
  457. function wrap(protocols) {
  458. // Default settings
  459. var exports = {
  460. maxRedirects: 21,
  461. maxBodyLength: 10 * 1024 * 1024,
  462. };
  463. // Wrap each protocol
  464. var nativeProtocols = {};
  465. Object.keys(protocols).forEach(function (scheme) {
  466. var protocol = scheme + ":";
  467. var nativeProtocol = nativeProtocols[protocol] = protocols[scheme];
  468. var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
  469. // Executes a request, following redirects
  470. function request(input, options, callback) {
  471. // Parse parameters, ensuring that input is an object
  472. if (isURL(input)) {
  473. input = spreadUrlObject(input);
  474. }
  475. else if (isString(input)) {
  476. input = spreadUrlObject(parseUrl(input));
  477. }
  478. else {
  479. callback = options;
  480. options = validateUrl(input);
  481. input = { protocol: protocol };
  482. }
  483. if (isFunction(options)) {
  484. callback = options;
  485. options = null;
  486. }
  487. // Set defaults
  488. options = Object.assign({
  489. maxRedirects: exports.maxRedirects,
  490. maxBodyLength: exports.maxBodyLength,
  491. }, input, options);
  492. options.nativeProtocols = nativeProtocols;
  493. if (!isString(options.host) && !isString(options.hostname)) {
  494. options.hostname = "::1";
  495. }
  496. assert.equal(options.protocol, protocol, "protocol mismatch");
  497. debug("options", options);
  498. return new RedirectableRequest(options, callback);
  499. }
  500. // Executes a GET request, following redirects
  501. function get(input, options, callback) {
  502. var wrappedRequest = wrappedProtocol.request(input, options, callback);
  503. wrappedRequest.end();
  504. return wrappedRequest;
  505. }
  506. // Expose the properties on the wrapped protocol
  507. Object.defineProperties(wrappedProtocol, {
  508. request: { value: request, configurable: true, enumerable: true, writable: true },
  509. get: { value: get, configurable: true, enumerable: true, writable: true },
  510. });
  511. });
  512. return exports;
  513. }
  514. function noop() { /* empty */ }
  515. function parseUrl(input) {
  516. var parsed;
  517. // istanbul ignore else
  518. if (useNativeURL) {
  519. parsed = new URL(input);
  520. }
  521. else {
  522. // Ensure the URL is valid and absolute
  523. parsed = validateUrl(url.parse(input));
  524. if (!isString(parsed.protocol)) {
  525. throw new InvalidUrlError({ input });
  526. }
  527. }
  528. return parsed;
  529. }
  530. function resolveUrl(relative, base) {
  531. // istanbul ignore next
  532. return useNativeURL ? new URL(relative, base) : parseUrl(url.resolve(base, relative));
  533. }
  534. function validateUrl(input) {
  535. if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) {
  536. throw new InvalidUrlError({ input: input.href || input });
  537. }
  538. if (/^\[/.test(input.host) && !/^\[[:0-9a-f]+\](:\d+)?$/i.test(input.host)) {
  539. throw new InvalidUrlError({ input: input.href || input });
  540. }
  541. return input;
  542. }
  543. function spreadUrlObject(urlObject, target) {
  544. var spread = target || {};
  545. for (var key of preservedUrlFields) {
  546. spread[key] = urlObject[key];
  547. }
  548. // Fix IPv6 hostname
  549. if (spread.hostname.startsWith("[")) {
  550. spread.hostname = spread.hostname.slice(1, -1);
  551. }
  552. // Ensure port is a number
  553. if (spread.port !== "") {
  554. spread.port = Number(spread.port);
  555. }
  556. // Concatenate path
  557. spread.path = spread.search ? spread.pathname + spread.search : spread.pathname;
  558. return spread;
  559. }
  560. function removeMatchingHeaders(regex, headers) {
  561. var lastValue;
  562. for (var header in headers) {
  563. if (regex.test(header)) {
  564. lastValue = headers[header];
  565. delete headers[header];
  566. }
  567. }
  568. return (lastValue === null || typeof lastValue === "undefined") ?
  569. undefined : String(lastValue).trim();
  570. }
  571. function createErrorType(code, message, baseClass) {
  572. // Create constructor
  573. function CustomError(properties) {
  574. // istanbul ignore else
  575. if (isFunction(Error.captureStackTrace)) {
  576. Error.captureStackTrace(this, this.constructor);
  577. }
  578. Object.assign(this, properties || {});
  579. this.code = code;
  580. this.message = this.cause ? message + ": " + this.cause.message : message;
  581. }
  582. // Attach constructor and set default properties
  583. CustomError.prototype = new (baseClass || Error)();
  584. Object.defineProperties(CustomError.prototype, {
  585. constructor: {
  586. value: CustomError,
  587. enumerable: false,
  588. },
  589. name: {
  590. value: "Error [" + code + "]",
  591. enumerable: false,
  592. },
  593. });
  594. return CustomError;
  595. }
  596. function destroyRequest(request, error) {
  597. for (var event of events) {
  598. request.removeListener(event, eventHandlers[event]);
  599. }
  600. request.on("error", noop);
  601. request.destroy(error);
  602. }
  603. function isSubdomain(subdomain, domain) {
  604. assert(isString(subdomain) && isString(domain));
  605. var dot = subdomain.length - domain.length - 1;
  606. return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
  607. }
  608. function isArray(value) {
  609. return value instanceof Array;
  610. }
  611. function isString(value) {
  612. return typeof value === "string" || value instanceof String;
  613. }
  614. function isFunction(value) {
  615. return typeof value === "function";
  616. }
  617. function isBuffer(value) {
  618. return typeof value === "object" && ("length" in value);
  619. }
  620. function isURL(value) {
  621. return URL && value instanceof URL;
  622. }
  623. function escapeRegex(regex) {
  624. return regex.replace(/[\]\\/()*+?.$]/g, "\\$&");
  625. }
  626. // Exports
  627. module.exports = wrap({ http: http, https: https });
  628. module.exports.wrap = wrap;