diff options
author | Zhidao HONG <z.hong@f5.com> | 2022-06-20 13:16:25 +0800 |
---|---|---|
committer | Zhidao HONG <z.hong@f5.com> | 2022-06-20 13:16:25 +0800 |
commit | 14dfa439eed1983693d7d128cc51c5e738a487d7 (patch) | |
tree | 771e4648406614b53c9195c4e66c78bf84520d27 /src/nxt_router.c | |
parent | fd38e69c3db9cda55fb24401c9eedbe18a05e962 (diff) | |
download | unit-14dfa439eed1983693d7d128cc51c5e738a487d7.tar.gz unit-14dfa439eed1983693d7d128cc51c5e738a487d7.tar.bz2 |
Router: introduced nxt_http_forward_t.
This makes the replacement of forwarded request header
like client_ip and protocol more generic.
It's a prerequirement for protocol replacement.
No functional changes.
Diffstat (limited to 'src/nxt_router.c')
-rw-r--r-- | src/nxt_router.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c index 00558d94..8487d239 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -109,8 +109,7 @@ static nxt_int_t nxt_router_conf_create(nxt_task_t *task, static nxt_int_t nxt_router_conf_process_static(nxt_task_t *task, nxt_router_conf_t *rtcf, nxt_conf_value_t *conf); static nxt_int_t nxt_router_conf_process_client_ip(nxt_task_t *task, - nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf, - nxt_conf_value_t *conf); + nxt_mp_t *mp, nxt_socket_conf_t *skcf, nxt_conf_value_t *conf); static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); static nxt_int_t nxt_router_apps_hash_test(nxt_lvlhsh_query_t *lhq, void *data); @@ -1885,10 +1884,12 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, } conf = nxt_conf_get_path(listener, &client_ip_path); - ret = nxt_router_conf_process_client_ip(task, tmcf, skcf, - conf); - if (nxt_slow_path(ret != NXT_OK)) { - return NXT_ERROR; + + if (conf != NULL) { + ret = nxt_router_conf_process_client_ip(task, mp, skcf, conf); + if (nxt_slow_path(ret != NXT_OK)) { + return NXT_ERROR; + } } #if (NXT_TLS) @@ -2124,30 +2125,22 @@ nxt_router_conf_process_static(nxt_task_t *task, nxt_router_conf_t *rtcf, static nxt_int_t -nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, +nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_mp_t *mp, nxt_socket_conf_t *skcf, nxt_conf_value_t *conf) { char c; size_t i; - nxt_mp_t *mp; uint32_t hash; nxt_str_t header; nxt_conf_value_t *source_conf, *header_conf, *recursive_conf; - nxt_http_client_ip_t *client_ip; + nxt_http_forward_t *forward; + nxt_http_forward_header_t *client_ip; nxt_http_route_addr_rule_t *source; static nxt_str_t header_path = nxt_string("/header"); static nxt_str_t source_path = nxt_string("/source"); static nxt_str_t recursive_path = nxt_string("/recursive"); - if (conf == NULL) { - skcf->client_ip = NULL; - - return NXT_OK; - } - - mp = tmcf->router_conf->mem_pool; - source_conf = nxt_conf_get_path(conf, &source_path); header_conf = nxt_conf_get_path(conf, &header_path); recursive_conf = nxt_conf_get_path(conf, &recursive_path); @@ -2156,8 +2149,8 @@ nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_router_temp_conf_t *tmcf return NXT_ERROR; } - client_ip = nxt_mp_zget(mp, sizeof(nxt_http_client_ip_t)); - if (nxt_slow_path(client_ip == NULL)) { + forward = nxt_mp_zget(mp, sizeof(nxt_http_forward_t)); + if (nxt_slow_path(forward == NULL)) { return NXT_ERROR; } @@ -2166,12 +2159,14 @@ nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_router_temp_conf_t *tmcf return NXT_ERROR; } - client_ip->source = source; + forward->source = source; + + client_ip = &forward->client_ip; nxt_conf_get_string(header_conf, &header); if (recursive_conf != NULL) { - client_ip->recursive = nxt_conf_get_boolean(recursive_conf); + forward->recursive = nxt_conf_get_boolean(recursive_conf); } client_ip->header = nxt_str_dup(mp, NULL, &header); @@ -2190,7 +2185,7 @@ nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_router_temp_conf_t *tmcf client_ip->header_hash = hash; - skcf->client_ip = client_ip; + skcf->client_ip = forward; return NXT_OK; } |