diff options
author | Zhidao HONG <z.hong@f5.com> | 2023-04-20 23:20:41 +0800 |
---|---|---|
committer | Zhidao HONG <z.hong@f5.com> | 2023-04-20 23:20:41 +0800 |
commit | 14d6d97bacf9b06ba340ebd4211b2f1b6ad417dd (patch) | |
tree | 68dd559c475cc0dffdf1254c75971fcae9a89ed5 /src/nxt_http_request.c | |
parent | 8843e30e8275aa70bf7eec11709cd5d12e32b4ae (diff) | |
download | unit-14d6d97bacf9b06ba340ebd4211b2f1b6ad417dd.tar.gz unit-14d6d97bacf9b06ba340ebd4211b2f1b6ad417dd.tar.bz2 |
HTTP: added basic URI rewrite.
This commit introduced the basic URI rewrite. It allows users to change request URI. Note the "rewrite" option ignores the contained query if any and the query from the request is preserverd.
An example:
"routes": [
{
"match": {
"uri": "/v1/test"
},
"action": {
"return": 200
}
},
{
"action": {
"rewrite": "/v1$uri",
"pass": "routes"
}
}
]
Reviewed-by: Alejandro Colomar <alx@nginx.com>
Diffstat (limited to 'src/nxt_http_request.c')
-rw-r--r-- | src/nxt_http_request.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c index e53b1ec8..48f7dbe3 100644 --- a/src/nxt_http_request.c +++ b/src/nxt_http_request.c @@ -555,9 +555,18 @@ void nxt_http_request_action(nxt_task_t *task, nxt_http_request_t *r, nxt_http_action_t *action) { + nxt_int_t ret; + if (nxt_fast_path(action != NULL)) { do { + if (action->rewrite != NULL) { + ret = nxt_http_rewrite(task, r, action); + if (nxt_slow_path(ret != NXT_OK)) { + break; + } + } + action = action->handler(task, r, action); if (action == NULL) { |