UNPKG

rekwest

Version:

The robust request library that humanity deserves 🌐

37 lines (36 loc) 823 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ackn = void 0; var _nodeTls = require("node:tls"); const ackn = options => new Promise((resolve, reject) => { const { url } = options; const socket = (0, _nodeTls.connect)({ ...options, ALPNProtocols: ['h2', 'http/1.1'], host: url.hostname, port: parseInt(url.port) || 443, servername: url.hostname }, () => { socket.off('error', reject); socket.off('timeout', reject); const { alpnProtocol } = socket; resolve({ ...options, alpnProtocol, createConnection() { return socket; }, h2: /h2c?/i.test(alpnProtocol), protocol: url.protocol }); }); socket.on('error', reject); socket.on('timeout', reject); }); exports.ackn = ackn;