Commit 2ea6c95a authored by Nathan Probst's avatar Nathan Probst

Allow rewrite status codes to be 2xx and 4xx.

parent c12847e5
...@@ -80,8 +80,8 @@ func rewriteParse(c *Controller) ([]rewrite.Rule, error) { ...@@ -80,8 +80,8 @@ func rewriteParse(c *Controller) ([]rewrite.Rule, error) {
return nil, c.ArgErr() return nil, c.ArgErr()
} }
status, _ = strconv.Atoi(c.Val()) status, _ = strconv.Atoi(c.Val())
if status < 400 || status > 499 { if status < 200 || (status > 299 && status < 400) || status > 499 {
return nil, c.Err("status must be 4xx") return nil, c.Err("status must be 2xx or 4xx")
} }
default: default:
return nil, c.ArgErr() return nil, c.ArgErr()
......
...@@ -137,6 +137,11 @@ func TestRewriteParse(t *testing.T) { ...@@ -137,6 +137,11 @@ func TestRewriteParse(t *testing.T) {
}`, false, []rewrite.Rule{ }`, false, []rewrite.Rule{
&rewrite.ComplexRule{Base: "/", To: "/to", Ifs: []rewrite.If{{A: "{path}", Operator: "is", B: "a"}}}, &rewrite.ComplexRule{Base: "/", To: "/to", Ifs: []rewrite.If{{A: "{path}", Operator: "is", B: "a"}}},
}}, }},
{`rewrite {
status 500
}`, true, []rewrite.Rule{
&rewrite.ComplexRule{},
}},
{`rewrite { {`rewrite {
status 400 status 400
}`, false, []rewrite.Rule{ }`, false, []rewrite.Rule{
...@@ -153,6 +158,22 @@ func TestRewriteParse(t *testing.T) { ...@@ -153,6 +158,22 @@ func TestRewriteParse(t *testing.T) {
}`, true, []rewrite.Rule{ }`, true, []rewrite.Rule{
&rewrite.ComplexRule{}, &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 { {`rewrite {
status 0 status 0
}`, true, []rewrite.Rule{ }`, true, []rewrite.Rule{
......
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