Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
441a8f5e
Commit
441a8f5e
authored
Aug 12, 2016
by
Volodymyr Galkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for duplicate status code entries in 'errors' directive
parent
4f6500c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
caddyhttp/errors/setup.go
caddyhttp/errors/setup.go
+8
-0
caddyhttp/errors/setup_test.go
caddyhttp/errors/setup_test.go
+11
-0
No files found.
caddyhttp/errors/setup.go
View file @
441a8f5e
...
...
@@ -123,12 +123,20 @@ func errorsParse(c *caddy.Controller) (*ErrorHandler, error) {
f
.
Close
()
if
what
==
"*"
{
if
handler
.
GenericErrorPage
!=
""
{
return
hadBlock
,
c
.
Errf
(
"Duplicate status code entry: %s"
,
what
)
}
handler
.
GenericErrorPage
=
where
}
else
{
whatInt
,
err
:=
strconv
.
Atoi
(
what
)
if
err
!=
nil
{
return
hadBlock
,
c
.
Err
(
"Expecting a numeric status code or '*', got '"
+
what
+
"'"
)
}
if
_
,
exists
:=
handler
.
ErrorPages
[
whatInt
];
exists
{
return
hadBlock
,
c
.
Errf
(
"Duplicate status code entry: %s"
,
what
)
}
handler
.
ErrorPages
[
whatInt
]
=
where
}
}
...
...
caddyhttp/errors/setup_test.go
View file @
441a8f5e
...
...
@@ -115,6 +115,15 @@ func TestErrorsParse(t *testing.T) {
503
:
"503.html"
,
},
}},
// Next two test cases is the detection of duplicate status codes
{
`errors {
503 503.html
503 503.html
}`
,
true
,
ErrorHandler
{}},
{
`errors {
* generic_error.html
* generic_error.html
}`
,
true
,
ErrorHandler
{}},
}
for
i
,
test
:=
range
tests
{
actualErrorsRule
,
err
:=
errorsParse
(
caddy
.
NewTestController
(
"http"
,
test
.
inputErrorsRules
))
...
...
@@ -123,6 +132,8 @@ func TestErrorsParse(t *testing.T) {
t
.
Errorf
(
"Test %d didn't error, but it should have"
,
i
)
}
else
if
err
!=
nil
&&
!
test
.
shouldErr
{
t
.
Errorf
(
"Test %d errored, but it shouldn't have; got '%v'"
,
i
,
err
)
}
else
{
continue
}
if
actualErrorsRule
.
LogFile
!=
test
.
expectedErrorHandler
.
LogFile
{
t
.
Errorf
(
"Test %d expected LogFile to be %s, but got %s"
,
...
...
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