@speedkit/cli 4.50.2 → 4.50.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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [4.50.3](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.50.2...v4.50.3) (2026-11-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **origin-request:** send the host header of an origin map entry ([22eff25](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/22eff257fbb89c6d2bb64d36f947cd39bb35e738))
|
|
7
|
+
|
|
1
8
|
## [4.50.2](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.50.1...v4.50.2) (2026-10-29)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -195,7 +195,11 @@ export function originFetch(url, init, options = {}) {
|
|
|
195
195
|
export function directOriginFetch(url, init, options = {}) {
|
|
196
196
|
const sent = new Headers(init?.headers);
|
|
197
197
|
const added = FETCH_DEFAULT_HEADERS.filter((name) => !sent.has(name));
|
|
198
|
-
const
|
|
198
|
+
const host = sent.get("host");
|
|
199
|
+
const interceptors = [withoutHeaders(added)];
|
|
200
|
+
if (host)
|
|
201
|
+
interceptors.push(withHost(host, new URL(url).origin));
|
|
202
|
+
const dispatcher = originDispatcher(options.tolerateLegacyTls === true).compose(interceptors);
|
|
199
203
|
const request = { ...init, dispatcher };
|
|
200
204
|
return undiciFetch(url, request);
|
|
201
205
|
}
|
|
@@ -216,6 +220,44 @@ function withoutHeaders(names) {
|
|
|
216
220
|
return dispatch({ ...opts, headers: Object.fromEntries(kept) }, handler);
|
|
217
221
|
};
|
|
218
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Sends the caller's `host` header, which fetch drops as a forbidden header. An origin map entry
|
|
225
|
+
* with `overrideHostHeader` needs it, because its reverse proxy routes by the original host.
|
|
226
|
+
*
|
|
227
|
+
* Only requests to `origin` get it, so a redirect to another origin keeps its own host.
|
|
228
|
+
*
|
|
229
|
+
* The TLS servername stays the connected host. Undici derives it from the `host` header otherwise,
|
|
230
|
+
* and the certificate of the mapped origin does not cover the original host.
|
|
231
|
+
*/
|
|
232
|
+
function withHost(host, origin) {
|
|
233
|
+
return (dispatch) => (opts, handler) => {
|
|
234
|
+
const connected = new URL(opts.origin);
|
|
235
|
+
if (connected.origin !== origin)
|
|
236
|
+
return dispatch(opts, handler);
|
|
237
|
+
const headers = Object.fromEntries(headerEntries(opts.headers).filter(([name]) => name.toLowerCase() !== "host"));
|
|
238
|
+
headers.host = host;
|
|
239
|
+
// Undici reads `servername` per request, but its types do not declare it.
|
|
240
|
+
const next = {
|
|
241
|
+
...opts,
|
|
242
|
+
headers,
|
|
243
|
+
servername: connected.hostname,
|
|
244
|
+
};
|
|
245
|
+
return dispatch(next, handler);
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/** Reads dispatch headers, which arrive as a plain object or as a flat name-value array. */
|
|
249
|
+
function headerEntries(headers) {
|
|
250
|
+
if (!headers)
|
|
251
|
+
return [];
|
|
252
|
+
if (Array.isArray(headers)) {
|
|
253
|
+
const entries = [];
|
|
254
|
+
for (let i = 0; i < headers.length; i += 2) {
|
|
255
|
+
entries.push([String(headers[i]), String(headers[i + 1])]);
|
|
256
|
+
}
|
|
257
|
+
return entries;
|
|
258
|
+
}
|
|
259
|
+
return Object.entries(headers).map(([name, value]) => [name, String(value)]);
|
|
260
|
+
}
|
|
219
261
|
function currentState() {
|
|
220
262
|
if (!state) {
|
|
221
263
|
applyOriginProxy();
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
2
|
import { describe, beforeEach, afterEach, it } from "mocha";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
3
4
|
import http from "node:http";
|
|
5
|
+
import https from "node:https";
|
|
6
|
+
import { join, dirname } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
4
8
|
import zlib from "node:zlib";
|
|
5
9
|
import { applyOriginProxy, chromeProxyFlag, findProxyInChromeFlags, originFetch, parseSocksProxy, PROXY_ENVIRONMENT_VARIABLE, resetOriginProxy, setOriginProxy, withOriginProxyFlag, } from "../origin-proxy.js";
|
|
10
|
+
/** Self-signed for `localhost`, only to serve the TLS spec. */
|
|
11
|
+
const FIXTURES = join(dirname(fileURLToPath(import.meta.url)), "fixtures");
|
|
12
|
+
const LOCALHOST_KEY = readFileSync(join(FIXTURES, "localhost.key"), "utf8");
|
|
13
|
+
const LOCALHOST_CERT = readFileSync(join(FIXTURES, "localhost.crt"), "utf8");
|
|
6
14
|
/** Sets or clears the enforcing environment variable. */
|
|
7
15
|
function setEnvironmentProxy(value) {
|
|
8
16
|
if (value === undefined) {
|
|
@@ -168,6 +176,10 @@ describe("origin proxy", () => {
|
|
|
168
176
|
if (request.url === "/redirect") {
|
|
169
177
|
response.writeHead(302, { location: "/" }).end();
|
|
170
178
|
}
|
|
179
|
+
else if (request.url.startsWith("/redirect-to?")) {
|
|
180
|
+
const location = decodeURIComponent(request.url.split("?")[1]);
|
|
181
|
+
response.writeHead(302, { location }).end();
|
|
182
|
+
}
|
|
171
183
|
else if (request.url === "/missing") {
|
|
172
184
|
response.writeHead(404).end(body);
|
|
173
185
|
}
|
|
@@ -208,6 +220,22 @@ describe("origin proxy", () => {
|
|
|
208
220
|
expect(headers["accept-language"]).to.equal("en-GB");
|
|
209
221
|
expect(headers.accept).to.equal("text/html");
|
|
210
222
|
});
|
|
223
|
+
it("sends the host header the caller sets", async () => {
|
|
224
|
+
const headers = await received("", {
|
|
225
|
+
headers: { Host: "www.example.com" },
|
|
226
|
+
});
|
|
227
|
+
expect(headers.host).to.equal("www.example.com");
|
|
228
|
+
});
|
|
229
|
+
it("keeps the host header off a redirect to another origin", async () => {
|
|
230
|
+
const other = echoUrl.replace("127.0.0.1", "localhost");
|
|
231
|
+
const response = await originFetch(`${echoUrl}redirect-to?${encodeURIComponent(other)}`, { headers: { host: "www.example.com" } });
|
|
232
|
+
expect(response.url).to.equal(other);
|
|
233
|
+
expect((await response.json()).host).to.equal(new URL(other).host);
|
|
234
|
+
});
|
|
235
|
+
it("sends the url's host without a host header", async () => {
|
|
236
|
+
const headers = await received();
|
|
237
|
+
expect(headers.host).to.equal(new URL(echoUrl).host);
|
|
238
|
+
});
|
|
211
239
|
it("drops the defaults when legacy tls is tolerated as well", async () => {
|
|
212
240
|
const headers = await received("", undefined, {
|
|
213
241
|
tolerateLegacyTls: true,
|
|
@@ -242,6 +270,31 @@ describe("origin proxy", () => {
|
|
|
242
270
|
expect(failure?.name).to.equal("TimeoutError");
|
|
243
271
|
});
|
|
244
272
|
});
|
|
273
|
+
describe("over tls", () => {
|
|
274
|
+
let secure;
|
|
275
|
+
let secureUrl;
|
|
276
|
+
beforeEach(async () => {
|
|
277
|
+
// Answers the host header and the servername the client sent.
|
|
278
|
+
secure = https.createServer({ key: LOCALHOST_KEY, cert: LOCALHOST_CERT }, (request, response) => response.end(JSON.stringify({
|
|
279
|
+
host: request.headers.host,
|
|
280
|
+
servername: request.socket.servername,
|
|
281
|
+
})));
|
|
282
|
+
await new Promise((resolve) => secure.listen(0, resolve));
|
|
283
|
+
secureUrl = `https://localhost:${secure.address().port}/`;
|
|
284
|
+
});
|
|
285
|
+
afterEach(() => {
|
|
286
|
+
secure.closeAllConnections();
|
|
287
|
+
secure.close();
|
|
288
|
+
});
|
|
289
|
+
it("keeps the connected host as servername when it overrides the host header", async () => {
|
|
290
|
+
// The self-signed certificate needs the tolerant transport.
|
|
291
|
+
const response = await originFetch(secureUrl, { headers: { host: "www.example.com" } }, { tolerateLegacyTls: true });
|
|
292
|
+
expect(await response.json()).to.deep.equal({
|
|
293
|
+
host: "www.example.com",
|
|
294
|
+
servername: "localhost",
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
245
298
|
it("routes through the installed proxy", async () => {
|
|
246
299
|
// Nothing listens on port 1, so a proxied request must fail to connect.
|
|
247
300
|
setOriginProxy({ type: 5, host: "127.0.0.1", port: 1 });
|
package/oclif.manifest.json
CHANGED