-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Currently, the only way we offer to rewrite the query part of the request URI is with the rewrite
handler (when it has a ?
in the target), or with uri replace
to perform replacements on the entire URI.
These options are limiting, because many query rewrite operations are difficult to perform with those.
For example, it's impossible (I can't think of a way) to remove a single query key from a request without knowing all the other possible query keys and re-including them all with &key={query.key}
in the rewrite.
It's also unwieldy to replace a specific query key with another (one way is with uri replace
but it's awkward and error-prone).
I think the solution is to add uri query
which supports multiple different types of operations on queries, similarly to the header
directive which has +
and -
and so on.
# add an additional `foo=bar` (even if there was already `foo=baz`)
uri query +foo bar
# overwrite `foo` with `foo=bar`
uri query foo bar
# delete `foo`
uri query -foo
# rename key `foo` to `bar`
uri query foo>bar
# set a default value (if the key is not already set)
uri query ?foo bar
# replace values in `foo`, changing `bar` to `baz`
uri query foo bar baz
# do multiple operations at once
uri query {
foo bar
bar baz
-baz
}
We may or may not actually implement all these operations, but I think most of them would be very nice to have.
Should this be its own directive instead of being added to uri
? To be discussed.