Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ceeb6c3

Browse files
authored
Mention header overriding behavior (vercel#16089)
Closes: vercel#16088
1 parent 2301331 commit ceeb6c3

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

docs/api-reference/next.config.js/headers.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = {
2727
},
2828
],
2929
},
30-
,
3130
]
3231
},
3332
}
@@ -38,6 +37,37 @@ module.exports = {
3837
- `source` is the incoming request path pattern.
3938
- `headers` is an array of header objects with the `key` and `value` properties.
4039

40+
## Header Overriding Behavior
41+
42+
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`.
43+
44+
```js
45+
module.exports = {
46+
async headers() {
47+
return [
48+
{
49+
source: '/:path*',
50+
headers: [
51+
{
52+
key: 'x-hello',
53+
value: 'there',
54+
},
55+
],
56+
},
57+
{
58+
source: '/hello',
59+
headers: [
60+
{
61+
key: 'x-hello',
62+
value: 'world',
63+
},
64+
],
65+
},
66+
],
67+
},
68+
}
69+
```
70+
4171
## Path Matching
4272

4373
Path matches are allowed, for example `/blog/:slug` will match `/blog/hello-world` (no nested paths):
@@ -59,8 +89,7 @@ module.exports = {
5989
},
6090
],
6191
},
62-
,
63-
]
92+
],
6493
},
6594
}
6695
```
@@ -86,8 +115,7 @@ module.exports = {
86115
},
87116
],
88117
},
89-
,
90-
]
118+
],
91119
},
92120
}
93121
```
@@ -109,7 +137,7 @@ module.exports = {
109137
},
110138
],
111139
},
112-
]
140+
],
113141
},
114142
}
115143
```

0 commit comments

Comments
 (0)