From 2ea6c95ac4845b67364c96bb16784ac77455c39a Mon Sep 17 00:00:00 2001 From: Nathan Probst Date: Mon, 22 Feb 2016 15:30:55 -0700 Subject: [PATCH] Allow rewrite status codes to be 2xx and 4xx. --- caddy/setup/rewrite.go | 4 ++-- caddy/setup/rewrite_test.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/caddy/setup/rewrite.go b/caddy/setup/rewrite.go index ab997d27..b270c93d 100644 --- a/caddy/setup/rewrite.go +++ b/caddy/setup/rewrite.go @@ -80,8 +80,8 @@ func rewriteParse(c *Controller) ([]rewrite.Rule, error) { return nil, c.ArgErr() } status, _ = strconv.Atoi(c.Val()) - if status < 400 || status > 499 { - return nil, c.Err("status must be 4xx") + if status < 200 || (status > 299 && status < 400) || status > 499 { + return nil, c.Err("status must be 2xx or 4xx") } default: return nil, c.ArgErr() diff --git a/caddy/setup/rewrite_test.go b/caddy/setup/rewrite_test.go index 29bfe997..1ce96aee 100644 --- a/caddy/setup/rewrite_test.go +++ b/caddy/setup/rewrite_test.go @@ -137,6 +137,11 @@ func TestRewriteParse(t *testing.T) { }`, false, []rewrite.Rule{ &rewrite.ComplexRule{Base: "/", To: "/to", Ifs: []rewrite.If{{A: "{path}", Operator: "is", B: "a"}}}, }}, + {`rewrite { + status 500 + }`, true, []rewrite.Rule{ + &rewrite.ComplexRule{}, + }}, {`rewrite { status 400 }`, false, []rewrite.Rule{ @@ -153,6 +158,22 @@ func TestRewriteParse(t *testing.T) { }`, true, []rewrite.Rule{ &rewrite.ComplexRule{}, }}, + {`rewrite { + status 200 + }`, false, []rewrite.Rule{ + &rewrite.ComplexRule{Base: "/", Regexp: regexp.MustCompile(".*"), Status: 200}, + }}, + {`rewrite { + to /to + status 200 + }`, false, []rewrite.Rule{ + &rewrite.ComplexRule{Base: "/", To: "/to", Regexp: regexp.MustCompile(".*"), Status: 200}, + }}, + {`rewrite { + status 199 + }`, true, []rewrite.Rule{ + &rewrite.ComplexRule{}, + }}, {`rewrite { status 0 }`, true, []rewrite.Rule{