mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Cleanups and panic prevention in tests.
This commit is contained in:
parent
4d5bc9fa6c
commit
1ed786f836
3 changed files with 11 additions and 4 deletions
|
@ -2,6 +2,7 @@ package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
"github.com/mholt/caddy/middleware/rewrite"
|
"github.com/mholt/caddy/middleware/rewrite"
|
||||||
|
@ -54,10 +55,11 @@ func rewriteParse(c *Controller) ([]rewrite.Rule, error) {
|
||||||
}
|
}
|
||||||
pattern = c.Val()
|
pattern = c.Val()
|
||||||
case "to":
|
case "to":
|
||||||
if !c.NextArg() {
|
args1 := c.RemainingArgs()
|
||||||
|
if len(args1) == 0 {
|
||||||
return nil, c.ArgErr()
|
return nil, c.ArgErr()
|
||||||
}
|
}
|
||||||
to = c.Val()
|
to = strings.Join(args1, " ")
|
||||||
case "ext":
|
case "ext":
|
||||||
args1 := c.RemainingArgs()
|
args1 := c.RemainingArgs()
|
||||||
if len(args1) == 0 {
|
if len(args1) == 0 {
|
||||||
|
|
|
@ -2,10 +2,11 @@ package rewrite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mholt/caddy/middleware"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mholt/caddy/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -19,7 +20,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func operatorError(operator string) error {
|
func operatorError(operator string) error {
|
||||||
return fmt.Errorf("Invalid operator", operator)
|
return fmt.Errorf("Invalid operator %v", operator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReplacer(r *http.Request) middleware.Replacer {
|
func newReplacer(r *http.Request) middleware.Replacer {
|
||||||
|
|
|
@ -54,6 +54,10 @@ func To(fs http.FileSystem, r *http.Request, to string) bool {
|
||||||
// isValidFile checks if file exists on the filesystem.
|
// isValidFile checks if file exists on the filesystem.
|
||||||
// if file ends with `/`, it is validated as a directory.
|
// if file ends with `/`, it is validated as a directory.
|
||||||
func isValidFile(fs http.FileSystem, file string) bool {
|
func isValidFile(fs http.FileSystem, file string) bool {
|
||||||
|
if fs == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
f, err := fs.Open(file)
|
f, err := fs.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue