Skip to content

Commit

Permalink
Merge pull request modcluster#190 from jajik/context-finding
Browse files Browse the repository at this point in the history
Cache context finding
  • Loading branch information
jajik authored Apr 22, 2024
2 parents 364e91a + fc4bed1 commit 60a3998
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
22 changes: 9 additions & 13 deletions native/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -459,14 +453,14 @@ 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++) {
if (length[j] == max) {
nbest++;
}
}

best = apr_palloc(r->pool, sizeof(node_context) * nbest);
nbest = 0;
for (j = 0; j < sizecontext; j++) {
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions native/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 60a3998

Please sign in to comment.