This commit is contained in:
Mateusz Gruszczyński committed 2026-11-23 12:23:41 +01:00
1 parent 54b2ac0838
commit 3b953dcdc6
23 files changed
+643 -29

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
// Load-balancing editor (vhost and location) with a consistent-hash distribution
// simulator. The pure helpers at the top mirror src/balance/model.rs (rendezvous
// scoring and hash keys) and are checked by tools/dev/test_balance_simulator.js.
// scoring and hash keys); keep them in step with tests/fixtures/balance_rendezvous_vectors.txt.
const lbSha256 = (() => {
const K = new Uint32Array([
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+26 -3
View File
@@ -1,6 +1,6 @@
"use strict";
let vhostCacheRulesEditor = null;
let basicEditor = null, locationsReader = () => [], aclControl = null, editing = null, revision = null, dirty = false, initialized = false, readBindings = () => [], readHosts = () => [], countryRatesReader = () => [], uaRatesReader = () => [], pagesEditor = null, stagedCertificates = [], uploading = false, draftEpoch = 0, backendHealthEditorControl = null, vhostBalancingControl = null;
let basicEditor = null, locationsReader = () => [], aclControl = null, editing = null, revision = null, dirty = false, initialized = false, readBindings = () => [], readHosts = () => [], countryRatesReader = () => [], uaRatesReader = () => [], pagesEditor = null, stagedCertificates = [], uploading = false, draftEpoch = 0, backendHealthEditorControl = null, vhostBalancingControl = null, vhostHeadersControl = null;
const chartHistory = new Map();
const backendTrafficHistory = new Map();
const backendRequestHistory = new Map();
@@ -87,6 +87,15 @@ function validateHeaders(value) {
}
} return value;
}
// Header value variables (src/headers/mod.rs Var::ALL); true = response rules only.
const HEADER_VARIABLES = [["srv_id", false], ["srv_url", false], ["location", false], ["vhost", false], ["lb_algorithm", false], ["hash_key", false], ["client_ip", false], ["country", false], ["req_id", false], ["method", false], ["host", false], ["path", false], ["cache_status", true], ["backend_time", true]];
const DIAGNOSTIC_PRESETS = [
{ key: "hdrPresetServedBy", direction: "response", rule: { op: "set", name: "X-Served-By", value: "%[srv_id]" } },
{ key: "hdrPresetLocation", direction: "response", rule: { op: "set", name: "X-Location", value: "%[location]" } },
{ key: "hdrPresetBalance", direction: "response", rule: { op: "set", name: "X-LB", value: "%[lb_algorithm] %[hash_key]" } },
{ key: "hdrPresetDebug", direction: "response", rule: { op: "set", name: "X-Debug", value: "%[vhost]/%[location] -> %[srv_id] (%[cache_status], %[backend_time])" } },
{ key: "hdrPresetUpstream", direction: "request", rule: { op: "set", name: "X-Shard", value: "%[srv_id]" } }
];
function headerEditors(parent, initial, target = read("headers"), onChange = changed) {
const holders = {}, adders = {}, emptyStates = {};
const renumber = direction => {
@@ -127,6 +136,20 @@ function headerEditors(parent, initial, target = read("headers"), onChange = cha
};
adders[direction] = add; for (const rule of initial[direction] || []) add(rule); renumber(direction);
block.append(button("addHeader", () => { add(); sync(); }, "quiet location-add-header"));
// %[variable] chips insert into the last focused value field of this direction.
const chips = el("div", undefined, "hdr-vars"); chips.append(text("span", "hdrVariables", "hdr-vars-label"));
let lastValue = null; rows.addEventListener("focusin", event => { if (event.target.name === "rule-value") lastValue = event.target; });
for (const [name, responseOnly] of HEADER_VARIABLES) {
if (responseOnly && direction === "request") continue;
const chip = button("hdrVariables", () => {
let target = lastValue?.isConnected && !lastValue.disabled ? lastValue : [...rows.querySelectorAll('[name="rule-value"]:not(:disabled)')].pop();
if (!target) { add({ op: "set", name: "", value: "" }); target = [...rows.querySelectorAll('[name="rule-value"]')].pop(); }
const token = `%[${name}]`, at = target.selectionStart ?? target.value.length;
target.value = target.value.slice(0, at) + token + target.value.slice(target.selectionEnd ?? at); target.focus(); target.setSelectionRange(at + token.length, at + token.length); lastValue = target; sync();
}, "quiet hdr-var");
delete chip.dataset.i18n; chip.textContent = `%[${name}]`; chip.title = t(`hdrVar_${name}`); chips.append(chip);
}
block.append(chips);
}
target.addEventListener("input", () => {
try {
@@ -139,8 +162,8 @@ function headerEditors(parent, initial, target = read("headers"), onChange = cha
target.setCustomValidity(""); onChange();
} catch (error) { target.setCustomValidity(error.message || t("headersInvalid")); }
});
note(parent, "locationHeadersHelp");
return { read: () => validateHeaders(JSON.parse(target.value)) };
note(parent, "locationHeadersHelp"); note(parent, "hdrVariablesHelp");
return { read: () => validateHeaders(JSON.parse(target.value)), add: (direction, rule) => { adders[direction](rule); renumber(direction); sync(); } };
}
function suspendDraft() {
const state = {
+9 -1
View File
@@ -211,6 +211,14 @@ function load(value = defaults(), migrationIds = [], show = true) {
field(g, "backend-header", "vhBackendHeader", value.backend_header === true, "checkbox", { switch: true });
field(g, "backend-timing-header", "vhBackendTimingHeader", value.backend_timing_header === true, "checkbox", { switch: true });
note(g, "vhBackendDiagnosticsHelp");
const diagnosticPresets = el("div", undefined, "vh-wide hdr-presets"); diagnosticPresets.append(text("span", "hdrPresets", "hdr-vars-label"));
for (const preset of DIAGNOSTIC_PRESETS) diagnosticPresets.append(button(preset.key, () => {
if (!vhostHeadersControl) return;
const current = vhostHeadersControl.read()[preset.direction] || [];
if (current.some(rule => rule.name.toLowerCase() === preset.rule.name.toLowerCase())) { toast(t("hdrPresetExists").replace("{name}", preset.rule.name)); return; }
vhostHeadersControl.add(preset.direction, { ...preset.rule }); toast(t("hdrPresetAdded").replace("{name}", preset.rule.name));
}, "quiet lb-preset"));
g.append(diagnosticPresets); note(g, "hdrPresetsHelp");
const proxyTimeouts = { ...defaultProxyTimeouts(), ...(value.proxy_timeouts || {}) };
g = group("vhProxyTimeouts");
field(g, "proxy-connect-timeout", "vhProxyConnectTimeout", proxyTimeouts.connect_timeout_seconds ?? 10, "number", { required: true, min: 1, max: 300 });
@@ -561,7 +569,7 @@ function load(value = defaults(), migrationIds = [], show = true) {
};
transformEnabled.addEventListener("change", syncTransform); customTransformExtensions.addEventListener("change", syncTransform); syncTransform();
note(transformOptions, "vhTransformHelp");
g = group("vhHeaders"); headerEditors(g, value.headers || {});
g = group("vhHeaders"); vhostHeadersControl = headerEditors(g, value.headers || {});
g = group("vhPages"); g.classList.add("vh-pages-grid"); pagesEditor = window.rustProxyPages.vhostEditor(g, value.pages || {});
initTabs(); dirty = false; if (latestStatus) renderStatus(latestStatus); if (show && !dialog.open) dialog.showModal();
+1 -1
View File
@@ -1,6 +1,6 @@
// Location conditions editor and the routing tester. The pure helpers mirror
// src/config/snapshot.rs (select_route) and src/vhost/conditions.rs and are checked
// against tests/fixtures/routing_conditions_cases.json by tools/dev/test_routing_tester.js.
// against the cases in tests/fixtures/routing_conditions_cases.json.
const RT_SOURCES = [["header", "rtSourceHeader"], ["cookie", "rtSourceCookie"], ["query", "rtSourceQuery"], ["method", "rtSourceMethod"], ["ip", "rtSourceIp"], ["host", "rtSourceHost"], ["country", "rtSourceCountry"]];
const RT_OPERATORS = [["equals", "rtOpEquals"], ["exists", "rtOpExists"], ["prefix", "rtOpPrefix"], ["suffix", "rtOpSuffix"], ["contains", "rtOpContains"], ["regex", "rtOpRegex"], ["cidr", "rtOpCidr"]];
function rtOperatorsFor(source) {