forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…logies#1146) Fixed TykTechnologies#639 This PR adds rewrite "triggers" on top of the existing rewrite functionality. These are essentially sub-matches to allow a rewrite rule to have variations. For example, for the URL `/foo/bar/baz` I want to rewrite to `/fooble/barble/bazble` if the query string variable `culprit` is set to `kronk`, but I want to redirect to `/foozle/barzle/bazzle` if the variable `culprit` is set to `yzma`. I can do this with the new URL Rewriter as follows: ``` { "url_rewrites": [ { "path": "/foo/bar/baz", "method": "GET", "match_pattern": "/foo/bar/baz", "rewrite_to": "/foo/bar/baz", "triggers": [ { "on": "any", "options": { "query_val_matches": { "culprit": { match_rx": "kronk" } } } "rewrite_to": "/fooble/barble/bazble" } { "on": "any", "options": { "query_val_matches": { "culprit": { match_rx": "yzma" } } } "rewrite_to": "/foozle/barzle/bazzle" } ] } ] } ``` Here if there is no trigger match, the rwrite will fallback to the parent `rewrite_to`, but if either of the other two are triggered, the rewrite target is changed. Each trigger also sets a context variable for each match it finds, these context vars can then be used in the rewrites, so the above example with context vars could be rewritten to: ``` { "url_rewrites": [ { "path": "/foo/bar/baz", "method": "GET", "match_pattern": "/foo/bar/baz", "rewrite_to": "/foo/bar/baz", "triggers": [ { "on": "any", "options": { "query_val_matches": { "culprit": { match_rx": "kronk" } } } "rewrite_to": "/fooble/barble/bazble?victim=$tyk_context.trigger-0-culprit-0" } { "on": "any", "options": { "query_val_matches": { "culprit": { match_rx": "yzma" } } } "rewrite_to": "/foozle/barzle/bazzle?victim=$tyk_context.trigger-1-culprit-0" } ] } ] } ``` Trigger contexts take the format: `$tyk_context.trigger-{n}-{name}-{i}` where `n` is the trigger index in the array, `nam` is the rx matcher name and `i` is the index of that match (since querystrings and headers can be arrays of values). The Trigger functionality supports: 1. Header matches 2. Query string variable/value matches 3. Path part matches, i.e. components of the path itself 4. Session meta data values 5. Payload matches For each trigger, the trigger can either use the `on: any` or `on: all` formatting, for `any`, if any one of the options in the trigger is true, the rewrite rule is fired. for `all`, all the options must be satisfied. This is limited to triggers, not groups of triggers, these will be evaluated one by one.
- Loading branch information
1 parent
8270030
commit e247d40
Showing
3 changed files
with
741 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.