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>
This commit is contained in:
Zhidao HONG
2023-04-20 23:20:41 +08:00
parent 8843e30e82
commit 14d6d97bac
11 changed files with 167 additions and 11 deletions

View File

@@ -669,6 +669,16 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_match_members[] = {
};
static nxt_conf_vldt_object_t nxt_conf_vldt_action_common_members[] = {
{
.name = nxt_string("rewrite"),
.type = NXT_CONF_VLDT_STRING,
},
NXT_CONF_VLDT_END
};
static nxt_conf_vldt_object_t nxt_conf_vldt_pass_action_members[] = {
{
.name = nxt_string("pass"),
@@ -677,7 +687,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_pass_action_members[] = {
.flags = NXT_CONF_VLDT_TSTR,
},
NXT_CONF_VLDT_END
NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members)
};
@@ -692,7 +702,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_return_action_members[] = {
.flags = NXT_CONF_VLDT_TSTR,
},
NXT_CONF_VLDT_END
NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members)
};
@@ -736,7 +746,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = {
#endif
},
NXT_CONF_VLDT_END
NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members)
};
@@ -747,7 +757,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_proxy_action_members[] = {
.validator = nxt_conf_vldt_proxy,
},
NXT_CONF_VLDT_END
NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members)
};