@dshn/agent 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +12 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -4848,6 +4848,13 @@ function e2eBootstrapTag(info) {
|
|
|
4848
4848
|
const json = JSON.stringify({ salt: info.salt, device: info.device }).replace(/</g, "\\u003c");
|
|
4849
4849
|
return `<script>(function (__dshnInfo) {${SHIM_BODY}})(${json})</script>`;
|
|
4850
4850
|
}
|
|
4851
|
+
function credentialManifestLinks(html) {
|
|
4852
|
+
return html.replace(/<link\b[^>]*>/gi, (tag) => {
|
|
4853
|
+
if (!/\brel\s*=\s*["']?manifest\b/i.test(tag) || /\bcrossorigin\b/i.test(tag))
|
|
4854
|
+
return tag;
|
|
4855
|
+
return tag.replace(/\s*\/?>$/, (end) => ` crossorigin="use-credentials"${end.trim() === "/>" ? " />" : ">"}`);
|
|
4856
|
+
});
|
|
4857
|
+
}
|
|
4851
4858
|
function injectE2EBootstrap(html, info) {
|
|
4852
4859
|
const tag = e2eBootstrapTag(info);
|
|
4853
4860
|
const head = /<head(\s[^>]*)?>/i.exec(html);
|
|
@@ -5625,16 +5632,17 @@ var AgentTunnel = class {
|
|
|
5625
5632
|
return;
|
|
5626
5633
|
}
|
|
5627
5634
|
const wantsDocument = method === "GET" && headers.some(([k, v]) => k.toLowerCase() === "accept" && v.includes("text/html"));
|
|
5628
|
-
|
|
5629
|
-
if (injectBootstrap)
|
|
5635
|
+
if (wantsDocument)
|
|
5630
5636
|
outHeaders["accept-encoding"] = "identity";
|
|
5631
5637
|
const req = http.request({ host: this.config.localHost, port: this.localPort(), method, path, headers: outHeaders }, (res) => {
|
|
5632
5638
|
const contentType = String(res.headers["content-type"] ?? "");
|
|
5633
|
-
if (
|
|
5639
|
+
if (wantsDocument && res.statusCode === 200 && /^text\/html\b/i.test(contentType)) {
|
|
5634
5640
|
const chunks = [];
|
|
5635
5641
|
res.on("data", (c) => chunks.push(c));
|
|
5636
5642
|
res.on("end", () => {
|
|
5637
|
-
|
|
5643
|
+
let html = credentialManifestLinks(Buffer.concat(chunks).toString("utf8"));
|
|
5644
|
+
if (this.e2eKey !== null)
|
|
5645
|
+
html = injectE2EBootstrap(html, { salt: this.e2eSalt, device: this.deviceId });
|
|
5638
5646
|
const body = Buffer.from(html, "utf8");
|
|
5639
5647
|
const resHeaders = filterHeaders(headerListFromRaw(res.rawHeaders), /* @__PURE__ */ new Set([...HOP_BY_HOP, "content-length", "content-encoding"]));
|
|
5640
5648
|
resHeaders.push(["content-length", String(body.length)]);
|