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
b7875698
Commit
b7875698
authored
Nov 24, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #359 from abiosoft/master
rewrite: Use middleware.Replacer for simple rule
parents
0b513699
016344ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
1 deletion
+7
-1
middleware/rewrite/rewrite.go
middleware/rewrite/rewrite.go
+5
-1
middleware/rewrite/rewrite_test.go
middleware/rewrite/rewrite_test.go
+2
-0
No files found.
middleware/rewrite/rewrite.go
View file @
b7875698
...
...
@@ -52,7 +52,11 @@ func (s SimpleRule) Rewrite(r *http.Request) bool {
// take note of this rewrite for internal use by fastcgi
// all we need is the URI, not full URL
r
.
Header
.
Set
(
headerFieldName
,
r
.
URL
.
RequestURI
())
r
.
URL
.
Path
=
s
.
To
// replace variables
to
:=
path
.
Clean
(
middleware
.
NewReplacer
(
r
,
nil
,
""
)
.
Replace
(
s
.
To
))
r
.
URL
.
Path
=
to
return
true
}
return
false
...
...
middleware/rewrite/rewrite_test.go
View file @
b7875698
...
...
@@ -17,6 +17,7 @@ func TestRewrite(t *testing.T) {
Rules
:
[]
Rule
{
NewSimpleRule
(
"/from"
,
"/to"
),
NewSimpleRule
(
"/a"
,
"/b"
),
NewSimpleRule
(
"/b"
,
"/b{uri}"
),
},
}
...
...
@@ -50,6 +51,7 @@ func TestRewrite(t *testing.T) {
}{
{
"/from"
,
"/to"
},
{
"/a"
,
"/b"
},
{
"/b"
,
"/b/b"
},
{
"/aa"
,
"/aa"
},
{
"/"
,
"/"
},
{
"/a?foo=bar"
,
"/b?foo=bar"
},
...
...
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