GUI-STUDIO commited on
Commit ·
8d2d19d
1
Parent(s): 2234c15
tests
Browse files- src/sub-router/test.ts +21 -25
src/sub-router/test.ts
CHANGED
|
@@ -53,9 +53,8 @@ const sub_router = new Elysia({ prefix: "/test" }).get("/foo", async (ctx) => {
|
|
| 53 |
const res_headers = res.headers;
|
| 54 |
const res_status = res.statusCode;
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
// 2. Forward and Filter Headers
|
| 59 |
const blacklisted_headers = [
|
| 60 |
"host",
|
| 61 |
"connection",
|
|
@@ -68,16 +67,32 @@ const sub_router = new Elysia({ prefix: "/test" }).get("/foo", async (ctx) => {
|
|
| 68 |
|
| 69 |
Object.entries(res_headers).forEach(([key, value]) => {
|
| 70 |
if (!blacklisted_headers.includes(key.toLowerCase()) && value) {
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|
| 73 |
});
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
// Convert the Node.js Readable stream to a Web ReadableStream (what Elysia/Bun expects)
|
| 76 |
-
const
|
| 77 |
-
// const
|
| 78 |
|
| 79 |
// Resolve the promise with the stream immediately
|
| 80 |
-
resolve(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
});
|
| 82 |
|
| 83 |
req.on("error", (err) => {
|
|
@@ -94,25 +109,6 @@ const sub_router = new Elysia({ prefix: "/test" }).get("/foo", async (ctx) => {
|
|
| 94 |
|
| 95 |
throw NS_error.F_create_error({ status, message });
|
| 96 |
}
|
| 97 |
-
|
| 98 |
-
// const res = await fetch(target.href, {
|
| 99 |
-
// headers: {
|
| 100 |
-
// host: "dl.gemlelispe.workers.dev",
|
| 101 |
-
// origin: "dl.gemlelispe.workers.dev",
|
| 102 |
-
// referer: "https://dl.vidsrc.vip/"
|
| 103 |
-
// },
|
| 104 |
-
// referrerPolicy: "no-referrer"
|
| 105 |
-
// });
|
| 106 |
-
|
| 107 |
-
// const res_status = res.status;
|
| 108 |
-
// const res_headers = res.headers;
|
| 109 |
-
|
| 110 |
-
// const res_headers_object = Object.fromEntries((res_headers as any).entries());
|
| 111 |
-
|
| 112 |
-
// return {
|
| 113 |
-
// res_status,
|
| 114 |
-
// res_headers: res_headers_object
|
| 115 |
-
// };
|
| 116 |
});
|
| 117 |
|
| 118 |
export const TestRouter = sub_router;
|
|
|
|
| 53 |
const res_headers = res.headers;
|
| 54 |
const res_status = res.statusCode;
|
| 55 |
|
| 56 |
+
const new_res_headers = new Headers();
|
| 57 |
|
|
|
|
| 58 |
const blacklisted_headers = [
|
| 59 |
"host",
|
| 60 |
"connection",
|
|
|
|
| 67 |
|
| 68 |
Object.entries(res_headers).forEach(([key, value]) => {
|
| 69 |
if (!blacklisted_headers.includes(key.toLowerCase()) && value) {
|
| 70 |
+
new_res_headers.set(key, value.toString());
|
| 71 |
+
|
| 72 |
+
if (["content-length"].includes(key.toLowerCase())) {
|
| 73 |
+
new_res_headers.set(`x-content-length`, value.toString());
|
| 74 |
+
}
|
| 75 |
}
|
| 76 |
});
|
| 77 |
|
| 78 |
+
set.status = res_status;
|
| 79 |
+
|
| 80 |
+
Object.entries(new_res_headers).forEach(([key, value]) => {
|
| 81 |
+
set.headers[key] = value.toString();
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
// Convert the Node.js Readable stream to a Web ReadableStream (what Elysia/Bun expects)
|
| 85 |
+
const web_stream = Readable.toWeb(res);
|
| 86 |
+
// const web_stream = Readable.toWeb(Readable.from([""]));
|
| 87 |
|
| 88 |
// Resolve the promise with the stream immediately
|
| 89 |
+
// resolve(web_stream);
|
| 90 |
+
resolve(
|
| 91 |
+
new Response(web_stream as any, {
|
| 92 |
+
status: res_status,
|
| 93 |
+
headers: new_res_headers
|
| 94 |
+
})
|
| 95 |
+
);
|
| 96 |
});
|
| 97 |
|
| 98 |
req.on("error", (err) => {
|
|
|
|
| 109 |
|
| 110 |
throw NS_error.F_create_error({ status, message });
|
| 111 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
});
|
| 113 |
|
| 114 |
export const TestRouter = sub_router;
|