reqly-cli 0.2.1 → 0.2.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/tunnel.mjs +24 -5
- package/package.json +1 -1
package/lib/tunnel.mjs
CHANGED
|
@@ -76,11 +76,25 @@ async function forwardRequest(localOrigin, capture) {
|
|
|
76
76
|
|
|
77
77
|
const start = Date.now();
|
|
78
78
|
|
|
79
|
+
// Clean headers — remove ones that break local forwarding
|
|
80
|
+
const cleanHeaders = {};
|
|
81
|
+
if (headers && typeof headers === "object") {
|
|
82
|
+
const skipHeaders = new Set(["host", "content-length", "transfer-encoding", "connection", "keep-alive", "upgrade", "http2-settings"]);
|
|
83
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
84
|
+
if (!skipHeaders.has(k.toLowerCase())) {
|
|
85
|
+
cleanHeaders[k] = v;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Don't send body for GET/HEAD
|
|
91
|
+
const hasBody = method && !["GET", "HEAD"].includes(method.toUpperCase());
|
|
92
|
+
|
|
79
93
|
try {
|
|
80
94
|
const res = await fetch(url, {
|
|
81
|
-
method: method || "
|
|
82
|
-
headers:
|
|
83
|
-
body:
|
|
95
|
+
method: method || "GET",
|
|
96
|
+
headers: cleanHeaders,
|
|
97
|
+
body: hasBody && body ? (typeof body === "string" ? body : JSON.stringify(body)) : undefined,
|
|
84
98
|
});
|
|
85
99
|
|
|
86
100
|
const resBody = await res.text();
|
|
@@ -213,9 +227,14 @@ async function pollForCaptures(serverUrl, token, tunnelId, localOrigin) {
|
|
|
213
227
|
try { headers = JSON.parse(headers); } catch { headers = {}; }
|
|
214
228
|
}
|
|
215
229
|
|
|
216
|
-
|
|
230
|
+
// Compute local path for display
|
|
231
|
+
let displayPath = capture.path || "/";
|
|
232
|
+
const binMatch = displayPath.match(/^\/api\/bin\/[^/]+(\/.*)?$/);
|
|
233
|
+
if (binMatch) displayPath = binMatch[1] || "/";
|
|
234
|
+
|
|
235
|
+
const methodStr = (method || "GET").toUpperCase().padEnd(6);
|
|
217
236
|
console.log(
|
|
218
|
-
`${DIM}[${timestamp()}]${RESET} ${CYAN}\u2192 ${methodStr}${RESET} ${
|
|
237
|
+
`${DIM}[${timestamp()}]${RESET} ${CYAN}\u2192 ${methodStr}${RESET} ${displayPath}`
|
|
219
238
|
);
|
|
220
239
|
|
|
221
240
|
// Forward and report
|