Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-static
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-static
Commits
8b718f1e
Commit
8b718f1e
authored
Nov 19, 2015
by
Terence Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove header appending, and the last header defined always wins
parent
64dc2b1b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
1 deletion
+50
-1
README.md
README.md
+19
-0
headers.rb
scripts/config/lib/ngx_mruby/headers.rb
+2
-1
foo.html
spec/fixtures/custom_headers_no_append/public_html/foo.html
+1
-0
index.html
.../fixtures/custom_headers_no_append/public_html/index.html
+1
-0
static.json
spec/fixtures/custom_headers_no_append/static.json
+15
-0
simple_spec.rb
spec/simple_spec.rb
+12
-0
No files found.
README.md
View file @
8b718f1e
...
...
@@ -132,6 +132,25 @@ For example, to enable CORS for all resources, you just need to enable it for al
}
```
##### Precedence
When there are header conflicts, the last header definition always wins. The headers do not get appended. For example,
```
json
{
"headers"
:
{
"/**"
:
{
"X-Foo"
:
"bar"
,
"X-Bar"
:
"baz"
},
"/foo"
:
{
"X-Foo"
:
"foo"
}
}
}
```
when accessing
`/foo`
,
`X-Foo`
will have the value
`"foo"`
and
`X-Bar`
will not be present.
### Route Ordering
*
Root Files
...
...
scripts/config/lib/ngx_mruby/headers.rb
View file @
8b718f1e
...
...
@@ -9,12 +9,13 @@ req = Nginx::Request.new
uri
=
req
.
var
.
uri
if
config
[
"headers"
]
config
[
"headers"
].
each
do
|
route
,
header_hash
|
config
[
"headers"
].
to_a
.
reverse
.
each
do
|
route
,
header_hash
|
if
Regexp
.
compile
(
"^
#{
NginxConfigUtil
.
to_regex
(
route
)
}
$"
)
=~
uri
header_hash
.
each
do
|
key
,
value
|
# value must be a string
req
.
headers_out
[
key
]
=
value
.
to_s
end
break
end
end
end
spec/fixtures/custom_headers_no_append/public_html/foo.html
0 → 100644
View file @
8b718f1e
foo
spec/fixtures/custom_headers_no_append/public_html/index.html
0 → 100644
View file @
8b718f1e
index
spec/fixtures/custom_headers_no_append/static.json
0 → 100644
View file @
8b718f1e
{
"headers"
:
{
"/"
:
{
"Cache-Control"
:
"no-cache"
},
"/**"
:
{
"X-Foo"
:
"false"
,
"X-Bar"
:
"blah"
},
"/foo.html"
:
{
"X-Foo"
:
"true"
}
},
"clean_urls"
:
true
}
spec/simple_spec.rb
View file @
8b718f1e
...
...
@@ -216,6 +216,18 @@ STATIC_JSON
end
end
describe
"conflicting headers"
do
let
(
:name
)
{
"custom_headers_no_append"
}
it
"should not append headers"
do
response
=
app
.
get
(
"/foo.html"
)
expect
(
response
[
"X-Foo"
]).
to
eq
(
"true"
)
expect
(
response
[
"X-Bar"
]).
to
eq
(
nil
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"foo"
)
end
end
describe
"wildcard paths"
do
let
(
:name
)
{
"custom_headers_wildcard"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment