Commit 261beb04 authored by Matthew Holt's avatar Matthew Holt

Moved rewrite middleware into its own package

parent b8c43e55
package middleware
import "net/http"
// Rewrite is middleware for rewriting requests internally to
// Package rewrite is middleware for rewriting requests internally to
// a different path.
func Rewrite(p parser) Middleware {
package rewrite
// Rewrite describes an internal location rewrite rule.
type rewrite struct {
From string
To string
}
import (
"net/http"
"github.com/mholt/caddy/middleware"
)
// New instantiates a new rewrite middleware.
func New(c middleware.Controller) (middleware.Middleware, error) {
var rewrites []rewrite
for p.Next() {
for c.Next() {
var rule rewrite
if !p.NextArg() {
return p.ArgErr()
if !c.NextArg() {
return nil, c.ArgErr()
}
rule.From = p.Val()
rule.From = c.Val()
if !p.NextArg() {
return p.ArgErr()
if !c.NextArg() {
return nil, c.ArgErr()
}
rule.To = p.Val()
rule.To = c.Val()
rewrites = append(rewrites, rule)
}
......@@ -40,5 +38,11 @@ func Rewrite(p parser) Middleware {
}
next(w, r)
}
}
}, nil
}
// rewrite describes an internal location rewrite rule.
type rewrite struct {
From string
To string
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment