Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve iterable peer headers (#5133)
[._.]/ Adam Eivyeb5d1298a3ba
diff --git a/server/lib/peerHttpClient.js b/server/lib/peerHttpClient.jsindex 2acf919546..725407b79d 100644--- a/server/lib/peerHttpClient.js+++ b/server/lib/peerHttpClient.js@@ -64,7 +64,7 @@ export function __resetSelfInstanceIdForTests() {* keep working.*/export async function peerFetch(url, options = {}, peer = null) {- const callerHeaders = options.headers || {};+ const callerHeaders = normalizeHeaders(options.headers);const finalOptions = {...options,headers: {@@ -75,6 +75,12 @@ export async function peerFetch(url, options = {}, peer = null) {return url.startsWith('https://') ? httpsFetch(url, finalOptions) : fetch(url, finalOptions);}+function normalizeHeaders(headers) {+ if (!headers) return {};+ if (typeof headers[Symbol.iterator] === 'function') return Object.fromEntries(headers);+ return { ...headers };+}+/*** Drop injected headers the caller already set under ANY casing. Object spread* is case-sensitive, so `{ 'X-PortOS-Instance-Id': a, 'x-portos-instance-id': b }`diff --git a/server/lib/peerHttpClient.test.js b/server/lib/peerHttpClient.test.jsindex d2661bdaf1..1722062376 100644--- a/server/lib/peerHttpClient.test.js+++ b/server/lib/peerHttpClient.test.js@@ -77,6 +77,26 @@ describe('peerHttpClient', () => {expect(sent).toEqual(['authorization']);});+ it('preserves a Headers instance while dropping the overridden Basic credential', async () => {+ await peerFetch('http://peer.example/x', {+ headers: new Headers({ Authorization: 'Bearer t', 'X-Request-Id': 'request-1' }),+ }, { auth: { password: 'pw' } });+ const sent = Object.keys(calls[0].options.headers).filter((k) => k.toLowerCase() === 'authorization');+ expect(sent).toEqual(['authorization']);+ expect(calls[0].options.headers.authorization).toBe('Bearer t');+ expect(calls[0].options.headers['x-request-id']).toBe('request-1');+ });++ it('preserves Map headers while dropping overridden injected headers', async () => {+ await peerFetch('http://peer.example/x', {+ headers: new Map([['x-portos-instance-id', 'explicit'], ['X-Request-Id', 'request-1']]),+ });+ const sent = Object.keys(calls[0].options.headers).filter((k) => k.toLowerCase() === 'x-portos-instance-id');+ expect(sent).toEqual(['x-portos-instance-id']);+ expect(calls[0].options.headers['x-portos-instance-id']).toBe('explicit');+ expect(calls[0].options.headers['X-Request-Id']).toBe('request-1');+ });+it('omits the header entirely when this install has no identity yet', async () => {selfInstanceId = 'unknown';__resetSelfInstanceIdForTests();