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
261beb04
Commit
261beb04
authored
Jan 29, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved rewrite middleware into its own package
parent
b8c43e55
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
middleware/rewrite/rewrite.go
middleware/rewrite/rewrite.go
+48
-0
No files found.
middleware/rewrite.go
→
middleware/rewrite
/rewrite
.go
View file @
261beb04
package
middleware
// Package rewrite is middleware for rewriting requests internally to
import
"net/http"
// Rewrite is middleware for rewriting requests internally to
// a different path.
// a different path.
func
Rewrite
(
p
parser
)
Middleware
{
package
rewrite
// Rewrite describes an internal location rewrite rule.
import
(
type
rewrite
struct
{
"net/http"
From
string
To
string
"github.com/mholt/caddy/middleware"
}
)
// New instantiates a new rewrite middleware.
func
New
(
c
middleware
.
Controller
)
(
middleware
.
Middleware
,
error
)
{
var
rewrites
[]
rewrite
var
rewrites
[]
rewrite
for
p
.
Next
()
{
for
c
.
Next
()
{
var
rule
rewrite
var
rule
rewrite
if
!
p
.
NextArg
()
{
if
!
c
.
NextArg
()
{
return
p
.
ArgErr
()
return
nil
,
c
.
ArgErr
()
}
}
rule
.
From
=
p
.
Val
()
rule
.
From
=
c
.
Val
()
if
!
p
.
NextArg
()
{
if
!
c
.
NextArg
()
{
return
p
.
ArgErr
()
return
nil
,
c
.
ArgErr
()
}
}
rule
.
To
=
p
.
Val
()
rule
.
To
=
c
.
Val
()
rewrites
=
append
(
rewrites
,
rule
)
rewrites
=
append
(
rewrites
,
rule
)
}
}
...
@@ -40,5 +38,11 @@ func Rewrite(p parser) Middleware {
...
@@ -40,5 +38,11 @@ func Rewrite(p parser) Middleware {
}
}
next
(
w
,
r
)
next
(
w
,
r
)
}
}
}
},
nil
}
// rewrite describes an internal location rewrite rule.
type
rewrite
struct
{
From
string
To
string
}
}
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