| 70839 | }; |
| 70840 | |
| 70841 | // node_modules/https-proxy-agent/dist/index.js |
| 70842 | var import_url = require("url"); |
| 70843 | |
| 70844 | // node_modules/https-proxy-agent/dist/parse-proxy-response.js |
| 70845 | var import_debug = __toESM(require_src2(), 1); |
| 70846 | var debug2 = (0, import_debug.default)("https-proxy-agent:parse-proxy-response"); |
| 70847 | function parseProxyResponse(socket) { |
| 70848 | return new Promise((resolve, reject) => { |
| 70849 | let buffersLength = 0; |
| 70850 | const buffers = []; |
| 70851 | function read() { |
| 70852 | const b7 = socket.read(); |
| 70853 | if (b7) |
| 70854 | ondata(b7); |
| 70855 | else |
| 70856 | socket.once("readable", read); |
| 70857 | } |
| 70858 | function cleanup() { |
| 70859 | socket.removeListener("end", onend); |
| 70860 | socket.removeListener("error", onerror); |
| 70861 | socket.removeListener("readable", read); |
| 70862 | } |
| 70863 | function onend() { |
| 70864 | cleanup(); |
| 70865 | debug2("onend"); |
| 70866 | reject(new Error("Proxy connection ended before receiving CONNECT response")); |
| 70867 | } |
| 70868 | function onerror(err) { |
| 70869 | cleanup(); |
| 70870 | debug2("onerror %o", err); |
| 70871 | reject(err); |
| 70872 | } |
| 70873 | function ondata(b7) { |
| 70874 | buffers.push(b7); |
| 70875 | buffersLength += b7.length; |
| 70876 | const buffered = Buffer.concat(buffers, buffersLength); |
| 70877 | const endOfHeaders = buffered.indexOf("\r\n\r\n"); |
| 70878 | if (endOfHeaders === -1) { |
| 70879 | debug2("have not received end of HTTP headers yet..."); |
| 70880 | read(); |
| 70881 | return; |
| 70882 | } |
| 70883 | const headerParts = buffered.slice(0, endOfHeaders).toString("ascii").split("\r\n"); |
| 70884 | const firstLine = headerParts.shift(); |
| 70885 | if (!firstLine) { |
| 70886 | socket.destroy(); |
| 70887 | return reject(new Error("No header received from proxy CONNECT response")); |
| 70888 | } |
| 70889 | const firstLineParts = firstLine.split(" "); |
| 70890 | const statusCode = +firstLineParts[1]; |
| 70891 | const statusText = firstLineParts.slice(2).join(" "); |
| 70892 | const headers = {}; |
| 70893 | for (const header of headerParts) { |
| 70894 | if (!header) |
| 70895 | continue; |
| 70896 | const firstColon = header.indexOf(":"); |
| 70897 | if (firstColon === -1) { |
| 70898 | socket.destroy(); |