From 125407889f52c058746b56ad586865f5395861cb Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Thu, 12 Feb 2026 17:01:19 +0100 Subject: [PATCH] fix fallback --- .../routes/helpers/get-component-fallback.ts | 4 +- ...y-routes-helpers-get-component-fallback.js | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/unit/registry-routes-helpers-get-component-fallback.js diff --git a/src/registry/routes/helpers/get-component-fallback.ts b/src/registry/routes/helpers/get-component-fallback.ts index 9eb10652..135513a9 100644 --- a/src/registry/routes/helpers/get-component-fallback.ts +++ b/src/registry/routes/helpers/get-component-fallback.ts @@ -83,8 +83,8 @@ export function getComponent( component: { name: string; version: string; parameters: IncomingHttpHeaders }, callback: (result: GetComponentResult) => void ): void { - // For some reason, undici doesn't like the content-type header - const { 'content-type': _, ...restHeaders } = headers; + // Avoid forwarding body/content negotiation headers that break fallback parsing. + const { 'content-type': _, 'accept-encoding': __, ...restHeaders } = headers; request(fallbackRegistryUrl, { method: 'POST', headers: { diff --git a/test/unit/registry-routes-helpers-get-component-fallback.js b/test/unit/registry-routes-helpers-get-component-fallback.js new file mode 100644 index 00000000..60c2fe01 --- /dev/null +++ b/test/unit/registry-routes-helpers-get-component-fallback.js @@ -0,0 +1,54 @@ +const expect = require('chai').expect; +const injectr = require('injectr'); +const sinon = require('sinon'); + +describe('registry : routes : helpers : get-component-fallback', () => { + it('should not forward accept-encoding header when fetching from fallback registry', (done) => { + const requestStub = sinon.stub().resolves({ + statusCode: 200, + body: { + json: sinon.stub().resolves([ + { + status: 200, + response: { name: 'my-component' } + } + ]) + } + }); + + const getComponentFallback = injectr( + '../../dist/registry/routes/helpers/get-component-fallback.js', + { + undici: { + request: requestStub + } + }, + { URL } + ); + + getComponentFallback.getComponent( + 'http://localhost:4000/', + { + 'accept-encoding': 'gzip, deflate, br', + 'content-type': 'application/json', + 'x-custom-header': 'test-value' + }, + { name: 'my-component', version: '1.0.0', parameters: {} }, + (result) => { + expect(result).to.eql({ + status: 200, + response: { name: 'my-component' } + }); + + const requestHeaders = requestStub.getCall(0).args[1].headers; + + expect(requestHeaders['accept-encoding']).to.equal(undefined); + expect(requestHeaders['content-type']).to.equal(undefined); + expect(requestHeaders['Content-Type']).to.equal('application/json'); + expect(requestHeaders['x-custom-header']).to.equal('test-value'); + + done(); + } + ); + }); +});