Skip to content

Commit

Permalink
Applied Replacer on all query keys and values
Browse files Browse the repository at this point in the history
  • Loading branch information
armadi1809 committed Feb 26, 2024
1 parent ddbebe2 commit 95e372a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions modules/caddyhttp/rewrite/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (rewr Rewrite) Rewrite(r *http.Request, repl *caddy.Replacer) bool {

// apply query operations
if rewr.QueryOperations != nil {
rewr.QueryOperations.do(r)
rewr.QueryOperations.do(r, repl)
}

// update the encoded copy of the URI
Expand Down Expand Up @@ -490,22 +490,23 @@ type queryOps struct {
Delete []string `json:"delete,omitempty"`
}

func (q *queryOps) do(r *http.Request) {
func (q *queryOps) do(r *http.Request, repl *caddy.Replacer) {
query := r.URL.Query()

for _, addParam := range q.Add {
key := addParam.Key
val := addParam.Val
key := repl.ReplaceAll(addParam.Key, "")
val := repl.ReplaceAll(addParam.Val, "")
query[key] = append(query[key], val)
}

for _, deleteParam := range q.Delete {
delete(query, deleteParam)
param := repl.ReplaceAll(deleteParam, "")
delete(query, param)
}

for _, setParam := range q.Set {
key := setParam.Key
val := setParam.Val
key := repl.ReplaceAll(setParam.Key, "")
val := repl.ReplaceAll(setParam.Val, "")
query[key] = []string{val}
}

Expand Down

0 comments on commit 95e372a

Please sign in to comment.