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
Łukasz Nowak
caddy
Commits
3c8b2b59
Commit
3c8b2b59
authored
Jul 21, 2016
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor condition keyword check refactor
parent
cf3ce491
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
16 deletions
+24
-16
caddyhttp/httpserver/condition.go
caddyhttp/httpserver/condition.go
+12
-5
caddyhttp/httpserver/condition_test.go
caddyhttp/httpserver/condition_test.go
+5
-2
caddyhttp/redirect/setup.go
caddyhttp/redirect/setup.go
+2
-3
caddyhttp/rewrite/setup.go
caddyhttp/rewrite/setup.go
+5
-6
No files found.
caddyhttp/httpserver/condition.go
View file @
3c8b2b59
...
@@ -6,12 +6,13 @@ import (
...
@@ -6,12 +6,13 @@ import (
"regexp"
"regexp"
"strings"
"strings"
"github.com/mholt/caddy
/caddyfile
"
"github.com/mholt/caddy"
)
)
// SetupIfMatcher parses `if` or `if_op` in the current dispenser block.
// SetupIfMatcher parses `if` or `if_op` in the current dispenser block.
// It returns a RequestMatcher and an error if any.
// It returns a RequestMatcher and an error if any.
func
SetupIfMatcher
(
c
caddyfile
.
Dispenser
)
(
RequestMatcher
,
error
)
{
func
SetupIfMatcher
(
controller
*
caddy
.
Controller
)
(
RequestMatcher
,
error
)
{
var
c
=
controller
.
Dispenser
// copy the dispenser
var
matcher
IfMatcher
var
matcher
IfMatcher
for
c
.
NextBlock
()
{
for
c
.
NextBlock
()
{
switch
c
.
Val
()
{
switch
c
.
Val
()
{
...
@@ -193,7 +194,13 @@ func (m IfMatcher) Or(r *http.Request) bool {
...
@@ -193,7 +194,13 @@ func (m IfMatcher) Or(r *http.Request) bool {
return
false
return
false
}
}
// IfMatcherKeyword returns if k is a keyword for 'if' config block.
// IfMatcherKeyword checks if the next value in the dispenser is a keyword for 'if' config block.
func
IfMatcherKeyword
(
k
string
)
bool
{
// If true, remaining arguments in the dispinser are cleard to keep the dispenser valid for use.
return
k
==
"if"
||
k
==
"if_op"
func
IfMatcherKeyword
(
c
*
caddy
.
Controller
)
bool
{
if
c
.
Val
()
==
"if"
||
c
.
Val
()
==
"if_op"
{
// clear remainig args
c
.
RemainingArgs
()
return
true
}
return
false
}
}
caddyhttp/httpserver/condition_test.go
View file @
3c8b2b59
...
@@ -243,7 +243,7 @@ func TestSetupIfMatcher(t *testing.T) {
...
@@ -243,7 +243,7 @@ func TestSetupIfMatcher(t *testing.T) {
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
c
:=
caddy
.
NewTestController
(
"http"
,
test
.
input
)
c
:=
caddy
.
NewTestController
(
"http"
,
test
.
input
)
c
.
Next
()
c
.
Next
()
matcher
,
err
:=
SetupIfMatcher
(
c
.
Dispenser
)
matcher
,
err
:=
SetupIfMatcher
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
if
err
==
nil
&&
test
.
shouldErr
{
t
.
Errorf
(
"Test %d didn't error, but it should have"
,
i
)
t
.
Errorf
(
"Test %d didn't error, but it should have"
,
i
)
}
else
if
err
!=
nil
&&
!
test
.
shouldErr
{
}
else
if
err
!=
nil
&&
!
test
.
shouldErr
{
...
@@ -277,8 +277,11 @@ func TestIfMatcherKeyword(t *testing.T) {
...
@@ -277,8 +277,11 @@ func TestIfMatcherKeyword(t *testing.T) {
{
"if_type"
,
false
},
{
"if_type"
,
false
},
{
"if_cond"
,
false
},
{
"if_cond"
,
false
},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
valid
:=
IfMatcherKeyword
(
test
.
keyword
)
c
:=
caddy
.
NewTestController
(
"http"
,
test
.
keyword
)
c
.
Next
()
valid
:=
IfMatcherKeyword
(
c
)
if
valid
!=
test
.
expected
{
if
valid
!=
test
.
expected
{
t
.
Errorf
(
"Test %d: expected %v found %v"
,
i
,
test
.
expected
,
valid
)
t
.
Errorf
(
"Test %d: expected %v found %v"
,
i
,
test
.
expected
,
valid
)
}
}
...
...
caddyhttp/redirect/setup.go
View file @
3c8b2b59
...
@@ -63,7 +63,7 @@ func redirParse(c *caddy.Controller) ([]Rule, error) {
...
@@ -63,7 +63,7 @@ func redirParse(c *caddy.Controller) ([]Rule, error) {
}
}
for
c
.
Next
()
{
for
c
.
Next
()
{
matcher
,
err
:=
httpserver
.
SetupIfMatcher
(
c
.
Dispenser
)
matcher
,
err
:=
httpserver
.
SetupIfMatcher
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -71,8 +71,7 @@ func redirParse(c *caddy.Controller) ([]Rule, error) {
...
@@ -71,8 +71,7 @@ func redirParse(c *caddy.Controller) ([]Rule, error) {
var
hadOptionalBlock
bool
var
hadOptionalBlock
bool
for
c
.
NextBlock
()
{
for
c
.
NextBlock
()
{
if
httpserver
.
IfMatcherKeyword
(
c
.
Val
())
{
if
httpserver
.
IfMatcherKeyword
(
c
)
{
c
.
RemainingArgs
()
continue
continue
}
}
...
...
caddyhttp/rewrite/setup.go
View file @
3c8b2b59
...
@@ -57,12 +57,15 @@ func rewriteParse(c *caddy.Controller) ([]httpserver.HandlerConfig, error) {
...
@@ -57,12 +57,15 @@ func rewriteParse(c *caddy.Controller) ([]httpserver.HandlerConfig, error) {
fallthrough
fallthrough
case
0
:
case
0
:
// Integrate request matcher for 'if' conditions.
// Integrate request matcher for 'if' conditions.
matcher
,
err
=
httpserver
.
SetupIfMatcher
(
c
.
Dispenser
)
matcher
,
err
=
httpserver
.
SetupIfMatcher
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
block
:
for
c
.
NextBlock
()
{
for
c
.
NextBlock
()
{
if
httpserver
.
IfMatcherKeyword
(
c
)
{
continue
}
switch
c
.
Val
()
{
switch
c
.
Val
()
{
case
"r"
,
"regexp"
:
case
"r"
,
"regexp"
:
if
!
c
.
NextArg
()
{
if
!
c
.
NextArg
()
{
...
@@ -90,10 +93,6 @@ func rewriteParse(c *caddy.Controller) ([]httpserver.HandlerConfig, error) {
...
@@ -90,10 +93,6 @@ func rewriteParse(c *caddy.Controller) ([]httpserver.HandlerConfig, error) {
return
nil
,
c
.
Err
(
"status must be 2xx or 4xx"
)
return
nil
,
c
.
Err
(
"status must be 2xx or 4xx"
)
}
}
default
:
default
:
if
httpserver
.
IfMatcherKeyword
(
c
.
Val
())
{
c
.
RemainingArgs
()
continue
block
}
return
nil
,
c
.
ArgErr
()
return
nil
,
c
.
ArgErr
()
}
}
}
}
...
...
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