From 2ea6c95ac4845b67364c96bb16784ac77455c39a Mon Sep 17 00:00:00 2001 From: Nathan Probst Date: Mon, 22 Feb 2016 15:30:55 -0700 Subject: [PATCH 1/2] 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{ From f4bb43781ccebce0ec69385c591680162c19cf01 Mon Sep 17 00:00:00 2001 From: Nathan Probst Date: Wed, 24 Feb 2016 10:28:06 -0700 Subject: [PATCH 2/2] Remove unneeded Regexp from tests. --- caddy/setup/rewrite_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/caddy/setup/rewrite_test.go b/caddy/setup/rewrite_test.go index 1ce96aee..d252ed90 100644 --- a/caddy/setup/rewrite_test.go +++ b/caddy/setup/rewrite_test.go @@ -145,13 +145,13 @@ func TestRewriteParse(t *testing.T) { {`rewrite { status 400 }`, false, []rewrite.Rule{ - &rewrite.ComplexRule{Base: "/", Regexp: regexp.MustCompile(".*"), Status: 400}, + &rewrite.ComplexRule{Base: "/", Status: 400}, }}, {`rewrite { to /to status 400 }`, false, []rewrite.Rule{ - &rewrite.ComplexRule{Base: "/", To: "/to", Regexp: regexp.MustCompile(".*"), Status: 400}, + &rewrite.ComplexRule{Base: "/", To: "/to", Status: 400}, }}, {`rewrite { status 399 @@ -161,13 +161,13 @@ func TestRewriteParse(t *testing.T) { {`rewrite { status 200 }`, false, []rewrite.Rule{ - &rewrite.ComplexRule{Base: "/", Regexp: regexp.MustCompile(".*"), Status: 200}, + &rewrite.ComplexRule{Base: "/", Status: 200}, }}, {`rewrite { to /to status 200 }`, false, []rewrite.Rule{ - &rewrite.ComplexRule{Base: "/", To: "/to", Regexp: regexp.MustCompile(".*"), Status: 200}, + &rewrite.ComplexRule{Base: "/", To: "/to", Status: 200}, }}, {`rewrite { status 199