fix(cli): skip headers with empty name when building request (#7869)

This commit is contained in:
Pragadesh-45
2026-05-06 13:57:29 +05:30
committed by GitHub
parent 5cf807b770
commit e92131ff8a
2 changed files with 66 additions and 1 deletions

View File

@@ -30,7 +30,7 @@ const prepareRequest = async (item = {}, collection = {}) => {
const disabledHeaders = [];
each(get(request, 'headers', []), (h) => {
if (h.enabled) {
if (h.enabled && h.name.length > 0) {
headers[h.name] = h.value;
if (h.name.toLowerCase() === 'content-type') {
contentTypeDefined = true;

View File

@@ -607,6 +607,71 @@ describe('prepare-request: prepareRequest', () => {
});
});
describe('Header filtering', () => {
it('skips headers with empty name', async () => {
const item = {
request: {
method: 'GET',
url: 'https://example.com',
headers: [
{ name: '', value: 'ghost', enabled: true },
{ name: 'X-Valid', value: 'yes', enabled: true }
]
}
};
const result = await prepareRequest(item);
expect(result.headers).not.toHaveProperty('');
expect(result.headers).toHaveProperty('X-Valid', 'yes');
});
it('skips disabled headers regardless of name', async () => {
const item = {
request: {
method: 'GET',
url: 'https://example.com',
headers: [
{ name: 'X-Disabled', value: 'nope', enabled: false },
{ name: 'X-Enabled', value: 'yes', enabled: true }
]
}
};
const result = await prepareRequest(item);
expect(result.headers).not.toHaveProperty('X-Disabled');
expect(result.headers).toHaveProperty('X-Enabled', 'yes');
});
it('includes all valid enabled headers', async () => {
const item = {
request: {
method: 'GET',
url: 'https://example.com',
headers: [
{ name: 'X-One', value: '1', enabled: true },
{ name: 'X-Two', value: '2', enabled: true }
]
}
};
const result = await prepareRequest(item);
expect(result.headers).toHaveProperty('X-One', '1');
expect(result.headers).toHaveProperty('X-Two', '2');
});
it('produces no headers when all have empty names', async () => {
const item = {
request: {
method: 'GET',
url: 'https://example.com',
headers: [
{ name: '', value: '', enabled: true },
{ name: '', value: 'some-value', enabled: true }
]
}
};
const result = await prepareRequest(item);
expect(Object.keys(result.headers).filter((k) => k === '')).toHaveLength(0);
});
});
describe('GraphQL request', () => {
it('keeps variables as string for interpolation', async () => {
const item = {