Skip to content

Commit

Permalink
feat: forward x-contnet-source-location to origin
Browse files Browse the repository at this point in the history
  • Loading branch information
buuhuu committed Feb 12, 2024
1 parent aa6a497 commit 7c104d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ async function run(request, ctx) {
reqHeaders.authorization = auth;
}

const sourceLocation = request.headers.get('x-content-source-location');
if (sourceLocation) {
reqHeaders['x-content-source-location'] = sourceLocation;
}

const res = await fetch(url, {
headers: reqHeaders,
});
Expand Down
17 changes: 16 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,29 @@ describe('Index Tests', () => {
nock('https://www.example.com', {
reqheaders: {
authorization: 'Bearer 1234',
'x-content-source-location': '/content/some-path/index?sig=signature&exp=2024-03-03T10:00:00.000Z',
},
})
.get('/index.html')
.replyWithFile(200, resolve(__testdir, 'fixtures', 'simple.html'), {
'last-modified': 'Sat, 22 Feb 2031 15:28:00 GMT',
});
const expected = await readFile(resolve(__testdir, 'fixtures', 'simple.md'), 'utf-8');
const result = await main(reqUrl('/index.html', { headers: { authorization: 'Bearer 1234' } }), { log: console, env: DUMMY_ENV });
const result = await main(
reqUrl(
'/index.html',
{
headers: {
authorization: 'Bearer 1234',
'x-content-source-location': '/content/some-path/index?sig=signature&exp=2024-03-03T10:00:00.000Z',
},
},
),
{
log: console,
env: DUMMY_ENV,
},
);
assert.strictEqual(result.status, 200);
assert.strictEqual((await result.text()).trim(), expected.trim());
assert.deepStrictEqual(result.headers.plain(), {
Expand Down

0 comments on commit 7c104d6

Please sign in to comment.