From ceeb6c3fce983cf96c6a9d8844a5cded2eedd9a3 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 11 Aug 2020 23:27:31 -0500 Subject: [PATCH] Mention header overriding behavior (#16089) Closes: https://github.com/vercel/next.js/issues/16088 --- docs/api-reference/next.config.js/headers.md | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/api-reference/next.config.js/headers.md b/docs/api-reference/next.config.js/headers.md index 4b854562e08e0..c066afeaf1a38 100644 --- a/docs/api-reference/next.config.js/headers.md +++ b/docs/api-reference/next.config.js/headers.md @@ -27,7 +27,6 @@ module.exports = { }, ], }, - , ] }, } @@ -38,6 +37,37 @@ module.exports = { - `source` is the incoming request path pattern. - `headers` is an array of header objects with the `key` and `value` properties. +## Header Overriding Behavior + +If two headers match the same path and set the same header key, the last header key will override the first. Using the below headers, the path `/hello` will result in the header `x-hello` being `world` due to the last header value set being `world`. + +```js +module.exports = { + async headers() { + return [ + { + source: '/:path*', + headers: [ + { + key: 'x-hello', + value: 'there', + }, + ], + }, + { + source: '/hello', + headers: [ + { + key: 'x-hello', + value: 'world', + }, + ], + }, + ], + }, +} +``` + ## Path Matching Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths): @@ -59,8 +89,7 @@ module.exports = { }, ], }, - , - ] + ], }, } ``` @@ -86,8 +115,7 @@ module.exports = { }, ], }, - , - ] + ], }, } ``` @@ -109,7 +137,7 @@ module.exports = { }, ], }, - ] + ], }, } ```