Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html): do not skip custom headers for 3xx responses #158

Merged
merged 1 commit into from
Oct 6, 2022
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: 4 additions & 0 deletions src/json-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export async function jsonPipe(state, req) {

// if still not found, return status
if (dataResponse.status !== 200) {
if (dataResponse.status < 500) {
await fetchConfigAll(state, req, dataResponse);
await setCustomResponseHeaders(state, req, dataResponse);
}
return dataResponse;
}
const data = dataResponse.body;
Expand Down
26 changes: 26 additions & 0 deletions test/json-pipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,32 @@ describe('JSON Pipe Test', () => {
});
});

it('applies custom header also to errors', async () => {
const state = createDefaultState();
state.s3Loader.reply(
'helix-content-bus',
'foobar/preview/metadata.json',
new PipelineResponse(JSON.stringify({
data: [
{ 'url': '/**', 'access-control-allow-origin': '*' },
{ 'url': '/**', 'content-security-policy': "default-src 'self'" },
],
}), {
headers: {
'last-modified': 'Wed, 11 Oct 2009 17:50:00 GMT',
},
}),
)
.reply('helix-content-bus', 'foobar/preview/en/index.json', null);
const resp = await jsonPipe(state, new PipelineRequest('https://not-found.json'));
assert.strictEqual(resp.status, 404);
const headers = Object.fromEntries(resp.headers.entries());
assert.deepStrictEqual(headers, {
'access-control-allow-origin': '*',
'content-security-policy': 'default-src \'self\'',
});
});

it('ignores newer last modified from metadata.json even if newer', async () => {
const state = createDefaultState();
state.s3Loader.reply(
Expand Down