aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/rewrite/rewrite.go
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2020-03-30 11:49:53 -0600
committerMatthew Holt <[email protected]>2020-03-30 11:49:53 -0600
commit105acfa08664c97460a6fe3fb49635618be5bcb2 (patch)
tree3c8ea6bc0fa1d335787a5b4852bd03ae50d4ef81 /modules/caddyhttp/rewrite/rewrite.go
parentdeba26d225c5b321a944439eb6b108117ac3d569 (diff)
downloadcaddy-105acfa08664c97460a6fe3fb49635618be5bcb2.tar.gz
caddy-105acfa08664c97460a6fe3fb49635618be5bcb2.zip
Keep type information with placeholders until replacements happen
Diffstat (limited to 'modules/caddyhttp/rewrite/rewrite.go')
-rw-r--r--modules/caddyhttp/rewrite/rewrite.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/modules/caddyhttp/rewrite/rewrite.go b/modules/caddyhttp/rewrite/rewrite.go
index ad054866a..3ba63c434 100644
--- a/modules/caddyhttp/rewrite/rewrite.go
+++ b/modules/caddyhttp/rewrite/rewrite.go
@@ -15,8 +15,10 @@
package rewrite
import (
+ "fmt"
"net/http"
"net/url"
+ "strconv"
"strings"
"github.com/caddyserver/caddy/v2"
@@ -208,11 +210,22 @@ func buildQueryString(qs string, repl *caddy.Replacer) string {
// consume the component and write the result
comp := qs[:end]
- comp, _ = repl.ReplaceFunc(comp, func(name, val string) (string, error) {
+ comp, _ = repl.ReplaceFunc(comp, func(name string, val interface{}) (interface{}, error) {
if name == "http.request.uri.query" && wroteVal {
return val, nil // already escaped
}
- return url.QueryEscape(val), nil
+ var valStr string
+ switch v := val.(type) {
+ case string:
+ valStr = v
+ case fmt.Stringer:
+ valStr = v.String()
+ case int:
+ valStr = strconv.Itoa(v)
+ default:
+ valStr = fmt.Sprintf("%+v", v)
+ }
+ return url.QueryEscape(valStr), nil
})
if end < len(qs) {
end++ // consume delimiter