diff options
author | Matthew Holt <[email protected]> | 2015-05-04 06:53:54 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2015-05-04 11:02:46 -0600 |
commit | 995edf05661c42399bb1469a657860e2ec8e7bf7 (patch) | |
tree | 94614623ff1496ef8c989ae29ea76d73a09e8a20 /middleware/rewrite | |
parent | 5f32f9b1c8f6054afcaed9e34bc937170a672757 (diff) | |
download | caddy-995edf05661c42399bb1469a657860e2ec8e7bf7.tar.gz caddy-995edf05661c42399bb1469a657860e2ec8e7bf7.zip |
Bringing in latest from master; refactoring under way
Diffstat (limited to 'middleware/rewrite')
-rw-r--r-- | middleware/rewrite/rewrite.go | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/middleware/rewrite/rewrite.go b/middleware/rewrite/rewrite.go index 9ce9381e9..870438dc2 100644 --- a/middleware/rewrite/rewrite.go +++ b/middleware/rewrite/rewrite.go @@ -8,22 +8,10 @@ import ( "github.com/mholt/caddy/middleware" ) -// New instantiates a new Rewrites middleware. -func New(c middleware.Controller) (middleware.Middleware, error) { - rewrites, err := parse(c) - if err != nil { - return nil, err - } - - return func(next middleware.Handler) middleware.Handler { - return Rewrite{Next: next, Rules: rewrites} - }, nil -} - // Rewrite is middleware to rewrite request locations internally before being handled. type Rewrite struct { Next middleware.Handler - Rules []RewriteRule + Rules []Rule } // ServeHTTP implements the middleware.Handler interface. @@ -37,29 +25,7 @@ func (rw Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) return rw.Next.ServeHTTP(w, r) } -func parse(c middleware.Controller) ([]RewriteRule, error) { - var rewrites []RewriteRule - - for c.Next() { - var rule RewriteRule - - if !c.NextArg() { - return rewrites, c.ArgErr() - } - rule.From = c.Val() - - if !c.NextArg() { - return rewrites, c.ArgErr() - } - rule.To = c.Val() - - rewrites = append(rewrites, rule) - } - - return rewrites, nil -} - -// RewriteRule describes an internal location rewrite rule. -type RewriteRule struct { +// A Rule describes an internal location rewrite rule. +type Rule struct { From, To string } |