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
0a04fa40
Commit
0a04fa40
authored
Jan 02, 2016
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oops. status code check should be after all validations.
parent
48d7f1ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
14 deletions
+30
-14
middleware/rewrite/rewrite.go
middleware/rewrite/rewrite.go
+5
-5
middleware/rewrite/rewrite_test.go
middleware/rewrite/rewrite_test.go
+25
-9
No files found.
middleware/rewrite/rewrite.go
View file @
0a04fa40
...
@@ -145,11 +145,6 @@ func (r *ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Rewrite
...
@@ -145,11 +145,6 @@ func (r *ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Rewrite
return
return
}
}
// if status is present, stop rewrite and return it.
if
r
.
Status
!=
0
{
return
RewriteStatus
}
// validate extensions
// validate extensions
if
!
r
.
matchExt
(
rPath
)
{
if
!
r
.
matchExt
(
rPath
)
{
return
return
...
@@ -183,6 +178,11 @@ func (r *ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Rewrite
...
@@ -183,6 +178,11 @@ func (r *ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Rewrite
}
}
}
}
// if status is present, stop rewrite and return it.
if
r
.
Status
!=
0
{
return
RewriteStatus
}
// attempt rewrite
// attempt rewrite
return
To
(
fs
,
req
,
r
.
To
,
replacer
)
return
To
(
fs
,
req
,
r
.
To
,
replacer
)
}
}
...
...
middleware/rewrite/rewrite_test.go
View file @
0a04fa40
...
@@ -107,17 +107,27 @@ func TestRewrite(t *testing.T) {
...
@@ -107,17 +107,27 @@ func TestRewrite(t *testing.T) {
}
}
}
}
statusTests
:=
[]
int
{
statusTests
:=
[]
struct
{
401
,
405
,
403
,
400
,
status
int
base
string
to
string
regexp
string
statusExpected
bool
}{
{
400
,
"/status"
,
""
,
""
,
true
},
{
400
,
"/ignore"
,
""
,
""
,
false
},
{
400
,
"/"
,
""
,
"^/ignore"
,
false
},
{
400
,
"/"
,
""
,
"(.*)"
,
true
},
{
400
,
"/status"
,
""
,
""
,
true
},
}
}
for
i
,
s
:=
range
statusTests
{
for
i
,
s
:=
range
statusTests
{
urlPath
:=
fmt
.
Sprintf
(
"/status%d"
,
i
)
urlPath
:=
fmt
.
Sprintf
(
"/status%d"
,
i
)
rule
,
err
:=
NewComplexRule
(
urlPath
,
""
,
""
,
s
,
nil
,
nil
)
rule
,
err
:=
NewComplexRule
(
s
.
base
,
s
.
regexp
,
s
.
to
,
s
.
statu
s
,
nil
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Test %d: No error expected for rule but found %v"
,
i
,
err
)
t
.
Fatalf
(
"Test %d: No error expected for rule but found %v"
,
i
,
err
)
}
}
rw
.
Rules
=
append
(
rw
.
Rules
,
rule
)
rw
.
Rules
=
[]
Rule
{
rule
}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
urlPath
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
urlPath
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Test %d: Could not create HTTP request: %v"
,
i
,
err
)
t
.
Fatalf
(
"Test %d: Could not create HTTP request: %v"
,
i
,
err
)
...
@@ -128,11 +138,17 @@ func TestRewrite(t *testing.T) {
...
@@ -128,11 +138,17 @@ func TestRewrite(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Test %d: No error expected for handler but found %v"
,
i
,
err
)
t
.
Fatalf
(
"Test %d: No error expected for handler but found %v"
,
i
,
err
)
}
}
if
rec
.
Body
.
String
()
!=
""
{
if
s
.
statusExpected
{
t
.
Errorf
(
"Test %d: Expected empty body but found %s"
,
i
,
rec
.
Body
.
String
())
if
rec
.
Body
.
String
()
!=
""
{
}
t
.
Errorf
(
"Test %d: Expected empty body but found %s"
,
i
,
rec
.
Body
.
String
())
if
code
!=
s
{
}
t
.
Errorf
(
"Text %d: Expected status code %d found %d"
,
i
,
s
,
code
)
if
code
!=
s
.
status
{
t
.
Errorf
(
"Test %d: Expected status code %d found %d"
,
i
,
s
.
status
,
code
)
}
}
else
{
if
code
!=
0
{
t
.
Errorf
(
"Test %d: Expected no status code found %d"
,
i
,
code
)
}
}
}
}
}
}
}
...
...
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