|
@ -22,6 +22,7 @@ import ( |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"reflect" |
|
|
"reflect" |
|
|
|
|
|
"strconv" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2" |
|
|
"github.com/caddyserver/caddy/v2" |
|
@ -462,14 +463,14 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) { |
|
|
if h.NextArg() { |
|
|
if h.NextArg() { |
|
|
code = h.Val() |
|
|
code = h.Val() |
|
|
} |
|
|
} |
|
|
if code == "permanent" { |
|
|
|
|
|
|
|
|
var body string |
|
|
|
|
|
switch code { |
|
|
|
|
|
case "permanent": |
|
|
code = "301" |
|
|
code = "301" |
|
|
} |
|
|
case "temporary", "": |
|
|
if code == "temporary" || code == "" { |
|
|
|
|
|
code = "302" |
|
|
code = "302" |
|
|
} |
|
|
case "html": |
|
|
var body string |
|
|
|
|
|
if code == "html" { |
|
|
|
|
|
// Script tag comes first since that will better imitate a redirect in the browser's
|
|
|
// Script tag comes first since that will better imitate a redirect in the browser's
|
|
|
// history, but the meta tag is a fallback for most non-JS clients.
|
|
|
// history, but the meta tag is a fallback for most non-JS clients.
|
|
|
const metaRedir = `<!DOCTYPE html> |
|
|
const metaRedir = `<!DOCTYPE html> |
|
@ -484,6 +485,15 @@ func parseRedir(h Helper) (caddyhttp.MiddlewareHandler, error) { |
|
|
` |
|
|
` |
|
|
safeTo := html.EscapeString(to) |
|
|
safeTo := html.EscapeString(to) |
|
|
body = fmt.Sprintf(metaRedir, safeTo, safeTo, safeTo, safeTo) |
|
|
body = fmt.Sprintf(metaRedir, safeTo, safeTo, safeTo, safeTo) |
|
|
|
|
|
code = "302" |
|
|
|
|
|
default: |
|
|
|
|
|
codeInt, err := strconv.Atoi(code) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, h.Errf("Not a supported redir code type or not valid integer: '%s'", code) |
|
|
|
|
|
} |
|
|
|
|
|
if codeInt < 300 || codeInt > 399 { |
|
|
|
|
|
return nil, h.Errf("Redir code not in the 3xx range: '%v'", codeInt) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return caddyhttp.StaticResponse{ |
|
|
return caddyhttp.StaticResponse{ |
|
|