diff --git a/src/utils/headers.js b/src/utils/headers.js index fae43b1ae43..944764185a2 100644 --- a/src/utils/headers.js +++ b/src/utils/headers.js @@ -67,6 +67,8 @@ const headersForPath = function (rules, path) { return pathObject } +const HEADER_SEPARATOR = ':' + const parseHeadersFile = function (filePath) { if (!fs.existsSync(filePath)) { return {} @@ -94,9 +96,9 @@ const parseHeadersFile = function (filePath) { throw new Error('path should come before headers') } - if (line.includes(':')) { - const [key = '', value = ''] = line.split(':', 2) - const [trimmedKey, trimmedValue] = [key.trim(), value.trim()] + if (line.includes(HEADER_SEPARATOR)) { + const [key = '', ...value] = line.split(HEADER_SEPARATOR) + const [trimmedKey, trimmedValue] = [key.trim(), value.join(HEADER_SEPARATOR).trim()] if (trimmedKey.length === 0 || trimmedValue.length === 0) { throw new Error(`invalid header at line: ${index}\n${line}\n`) } diff --git a/src/utils/headers.test.js b/src/utils/headers.test.js index 59329808e57..b704a4f9a9c 100644 --- a/src/utils/headers.test.js +++ b/src/utils/headers.test.js @@ -35,6 +35,10 @@ const headers = [ path: '/directory/*/test.html', headers: ['X-Frame-Options: test'], }, + { + path: '/with-colon', + headers: ['Custom-header: http://www.example.com'], + }, ] test.before(async (t) => { @@ -99,6 +103,9 @@ test('_headers: validate rules', (t) => { '/directory/*/test.html': { 'X-Frame-Options': ['test'], }, + '/with-colon': { + 'Custom-header': ['http://www.example.com'], + }, }) })