fix: preserve proxy script crlf escapes

This commit is contained in:
Codex
2026-05-31 15:14:03 +08:00
parent 6266f4240e
commit ee0e5f84e6
+9 -9
View File
@@ -1119,7 +1119,7 @@ socket.setTimeout(10000, () => {
});
socket.on("connect", () => {
socket.write("CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1\r\nHost: " + targetHost + ":" + targetPort + "\r\nProxy-Connection: Keep-Alive\r\n\r\n");
socket.write("CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1\\r\\nHost: " + targetHost + ":" + targetPort + "\\r\\nProxy-Connection: Keep-Alive\\r\\n\\r\\n");
});
socket.on("error", (error) => {
@@ -1129,10 +1129,10 @@ socket.on("error", (error) => {
function onData(chunk) {
buffer = Buffer.concat([buffer, chunk]);
const headerEnd = buffer.indexOf("\r\n\r\n");
const headerEnd = buffer.indexOf("\\r\\n\\r\\n");
if (headerEnd === -1 && buffer.length < 8192) return;
const head = buffer.slice(0, headerEnd + 4).toString("latin1");
const statusLine = head.split("\r\n", 1)[0] || "";
const statusLine = head.split("\\r\\n", 1)[0] || "";
const statusCode = Number.parseInt(statusLine.split(" ")[1] || "", 10);
if (!statusLine.startsWith("HTTP/1.") || !Number.isInteger(statusCode) || statusCode < 200 || statusCode > 299) {
console.error("proxy CONNECT rejected: " + (statusLine || "missing-status"));
@@ -3146,14 +3146,14 @@ if (!proxyHost || !Number.isInteger(proxyPort) || !targetHost || !Number.isInteg
const socket = net.createConnection({ host: proxyHost, port: proxyPort });
let buffer = Buffer.alloc(0);
socket.setTimeout(10000, () => { socket.destroy(); process.exit(65); });
socket.on("connect", () => socket.write("CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1\r\nHost: " + targetHost + ":" + targetPort + "\r\nProxy-Connection: Keep-Alive\r\n\r\n"));
socket.on("connect", () => socket.write("CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1\\r\\nHost: " + targetHost + ":" + targetPort + "\\r\\nProxy-Connection: Keep-Alive\\r\\n\\r\\n"));
socket.on("error", () => process.exit(66));
function onData(chunk) {
buffer = Buffer.concat([buffer, chunk]);
const headerEnd = buffer.indexOf("\r\n\r\n");
const headerEnd = buffer.indexOf("\\r\\n\\r\\n");
if (headerEnd === -1 && buffer.length < 8192) return;
const head = buffer.slice(0, headerEnd + 4).toString("latin1");
const statusLine = head.split("\r\n", 1)[0] || "";
const statusLine = head.split("\\r\\n", 1)[0] || "";
const statusCode = Number.parseInt(statusLine.split(" ")[1] || "", 10);
if (!statusLine.startsWith("HTTP/1.") || !Number.isInteger(statusCode) || statusCode < 200 || statusCode > 299) { socket.destroy(); process.exit(67); }
socket.off("data", onData);
@@ -3392,14 +3392,14 @@ if (!proxyHost || !Number.isInteger(proxyPort) || !targetHost || !Number.isInteg
const socket = net.createConnection({ host: proxyHost, port: proxyPort });
let buffer = Buffer.alloc(0);
socket.setTimeout(10000, () => { socket.destroy(); process.exit(65); });
socket.on("connect", () => socket.write("CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1\r\nHost: " + targetHost + ":" + targetPort + "\r\nProxy-Connection: Keep-Alive\r\n\r\n"));
socket.on("connect", () => socket.write("CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1\\r\\nHost: " + targetHost + ":" + targetPort + "\\r\\nProxy-Connection: Keep-Alive\\r\\n\\r\\n"));
socket.on("error", () => process.exit(66));
function onData(chunk) {
buffer = Buffer.concat([buffer, chunk]);
const headerEnd = buffer.indexOf("\r\n\r\n");
const headerEnd = buffer.indexOf("\\r\\n\\r\\n");
if (headerEnd === -1 && buffer.length < 8192) return;
const head = buffer.slice(0, headerEnd + 4).toString("latin1");
const statusLine = head.split("\r\n", 1)[0] || "";
const statusLine = head.split("\\r\\n", 1)[0] || "";
const statusCode = Number.parseInt(statusLine.split(" ")[1] || "", 10);
if (!statusLine.startsWith("HTTP/1.") || !Number.isInteger(statusCode) || statusCode < 200 || statusCode > 299) { socket.destroy(); process.exit(67); }
socket.off("data", onData);