From fc4bed14c785ae62f13e620f091b5f2db3ef2c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Tue, 9 Jan 2024 13:17:47 +0100 Subject: [PATCH] Change context search to cache the results Fix missing doxygen comment for an argument --- native/common/common.c | 22 +++++++++------------- native/include/common.h | 1 + 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/native/common/common.c b/native/common/common.c index 6fffbe34d..79012449f 100644 --- a/native/common/common.c +++ b/native/common/common.c @@ -353,18 +353,12 @@ node_context *find_node_context_host(request_rec *r, const proxy_balancer *balan node_context *best; int nbest; const char *uri = NULL; - const char *luri = NULL; + const char *luri = r->uri; - /* use r->uri (trans) or r->filename (after canon or rewrite) */ - if (r->filename) { - const char *scheme = strstr(r->filename, "://"); - if (scheme) { - luri = ap_strchr_c(scheme + 3, '/'); - } - } - if (!luri) { - luri = r->uri; + if (apr_table_get(r->notes, "proxy-context")) { + return (node_context *)apr_table_get(r->notes, "proxy-context"); } + uri = ap_strchr_c(luri, '?'); if (uri) { uri = apr_pstrndup(r->pool, luri, uri - luri); @@ -459,7 +453,6 @@ node_context *find_node_context_host(request_rec *r, const proxy_balancer *balan return NULL; } - /* find the best matching contexts */ nbest = 1; for (j = 0; j < sizecontext; j++) { @@ -467,6 +460,7 @@ node_context *find_node_context_host(request_rec *r, const proxy_balancer *balan nbest++; } } + best = apr_palloc(r->pool, sizeof(node_context) * nbest); nbest = 0; for (j = 0; j < sizecontext; j++) { @@ -477,12 +471,12 @@ node_context *find_node_context_host(request_rec *r, const proxy_balancer *balan /* Check status */ switch (status[j]) { case ENABLED: - ok = -1; + ok = 1; break; case DISABLED: /* Only the request with sessionid ok for it */ if (hassession_byname(r, context->node, route, node_table)) { - ok = -1; + ok = 1; } break; } @@ -497,6 +491,8 @@ node_context *find_node_context_host(request_rec *r, const proxy_balancer *balan return NULL; } best[nbest].node = -1; + /* Save the result */ + apr_table_setn(r->notes, "proxy-context", (char *)best); return best; } diff --git a/native/include/common.h b/native/include/common.h index 64566b5f9..c21123b2f 100644 --- a/native/include/common.h +++ b/native/include/common.h @@ -195,6 +195,7 @@ nodeinfo_t *table_get_node_route(proxy_node_table *node_table, char *route, int * @param r the request_rec * @param vhost_table table of host virtual hosts * @param context_table table of contexts + * @param use_alias compare alias with server_name * @return the balancer name or NULL if not found */ const char *get_context_host_balancer(request_rec *r, proxy_vhost_table *vhost_table,