Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/registry/routes/helpers/get-component-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
54 changes: 54 additions & 0 deletions test/unit/registry-routes-helpers-get-component-fallback.js
Original file line number Diff line number Diff line change
@@ -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();
}
);
});
});