diff --git a/src/steps/set-x-surrogate-key-header.js b/src/steps/set-x-surrogate-key-header.js index 62a5aacd..8a0f10bd 100644 --- a/src/steps/set-x-surrogate-key-header.js +++ b/src/steps/set-x-surrogate-key-header.js @@ -44,14 +44,20 @@ export default async function setXSurrogateKeyHeader(state, req, res) { const { contentBusId, owner, repo, ref, } = state; - const hash = await getPathKey(state); - const keys = [ - hash, - `${contentBusId}_metadata`, - `${ref}--${repo}--${owner}_head`, - contentBusId, - ]; + const isCode = state.content.sourceBus === 'code'; + + const keys = []; + const hash = await getPathKey(state); + if (isCode) { + keys.push(await computeSurrogateKey(`${ref}--${repo}--${owner}${state.info.path}`)); + keys.push(`${ref}--${repo}--${owner}_code`); + } else { + keys.push(hash); + keys.push(`${contentBusId}_metadata`); + keys.push(`${ref}--${repo}--${owner}_head`); + keys.push(contentBusId); + } // for folder-mapped resources, we also need to include the surrogate key of the mapped metadata if (state.mapped) { keys.push(`${hash}_metadata`); diff --git a/test/html-pipe.test.js b/test/html-pipe.test.js index 2c23c8b5..ee9ae4af 100644 --- a/test/html-pipe.test.js +++ b/test/html-pipe.test.js @@ -221,7 +221,7 @@ describe('HTML Pipe Test', () => { assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), { 'content-type': 'text/html; charset=utf-8', 'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT', - 'x-surrogate-key': 'kvcvppnfHtt5omSX foo-id_metadata super-test--helix-pages--adobe_head foo-id', + 'x-surrogate-key': 'oAJVhwwmjc53GpIM super-test--helix-pages--adobe_code', }); }); }); diff --git a/test/rendering.test.js b/test/rendering.test.js index 7c6a0128..9204b72d 100644 --- a/test/rendering.test.js +++ b/test/rendering.test.js @@ -620,7 +620,7 @@ describe('Rendering', () => { 'access-control-allow-origin': '*', 'content-type': 'text/html; charset=utf-8', 'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT', - 'x-surrogate-key': 'SUhNxkR2spoxY489 foo-id_metadata super-test--helix-pages--adobe_head foo-id', + 'x-surrogate-key': 'OjUJ-F2DzRC3rMht super-test--helix-pages--adobe_code', link: '; rel=modulepreload; as=script; crossorigin=use-credentials', }); }); @@ -673,7 +673,7 @@ describe('Rendering', () => { 'access-control-allow-origin': '*', 'content-type': 'text/html; charset=utf-8', 'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT', - 'x-surrogate-key': 'VmeAc3K7QsCRzj5Z foo-id_metadata super-test--helix-pages--adobe_head foo-id', + 'x-surrogate-key': 'OhRDjcpvIRqjAeih super-test--helix-pages--adobe_code', link: '; rel=modulepreload; as=script; crossorigin=use-credentials', }); });