Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge the HTTP and session review fixes (#6862 round 1) into the WebSocket branch

Bugfixer 2be645615d54a
diff --cc src/lib/e2e/http.ts
index 8ba9fc38ff,c0c336afcd..c5aae6196b
--- a/src/lib/e2e/http.ts
+++ b/src/lib/e2e/http.ts
@@@ -37,19 -36,16 +37,21 @@@ export function headStart(method: strin
if (!path.startsWith("/") || [...path].some((char) => char <= " " || char === "\x7f" || char === "#")) {
throw new TypeError("e2e http: path must be origin-form with no spaces, controls or fragment");
}
- let head = `${method} ${path} HTTP/1.1\r\nHost: companion\r\n`;
+ // A path's non-ASCII goes out percent-encoded UTF-8, as fetch's URL parser sends it.
+ const target = path.replace(/[\u0080-\uffff]+/g, (run) => Array.from(utf8(run), (byte) => `%${byte.toString(16).toUpperCase().padStart(2, "0")}`).join(""));
+ let head = `${method} ${target} HTTP/1.1\r\nHost: companion\r\n`;
// Headers already refuses names that are not tokens and values with CR, LF or NUL.
for (const [name, value] of headers) {
- if (OWN.has(name)) throw new TypeError(`e2e http: ${name} is set by the stream client`);
+ if (OWN.has(name) || name.startsWith("sec-websocket-")) throw new TypeError(`e2e http: ${name} is set by the stream client`);
head += `${name}: ${value}\r\n`;
}
- if (length !== null) head += `Content-Length: ${length}\r\n`;
- return `${head}Connection: close\r\n\r\n`;
+ return head;
+}
+
+/** The whole head of a plain request. */
+export function requestHead(method: string, path: string, headers: Headers, length: number | null): string {
+ const head = headStart(method, path, headers);
+ return `${head}${length !== null ? `Content-Length: ${length}\r\n` : ""}Connection: close\r\n\r\n`;
}
/** Reads a stream's bytes with the leftover of the last read kept for the next parse. */