Skip to content

Commit 44dd11e

Browse files
authored
Merge pull request #302 from jajik/issue-297
Add `UseNocanon` to mod_lbmethod_cluster, fix testsuite to use the right module
2 parents 778b7b7 + a2f7b0a commit 44dd11e

15 files changed

Lines changed: 254 additions & 31 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ jobs:
244244
- name: Setup dependencies
245245
run: |
246246
sudo apt-get update -y
247-
sudo apt-get install -y docker maven git curl iproute2
247+
sudo apt-get install -y docker maven git curl iproute2 wcstools
248248
cd test
249249
sh setup-dependencies.sh
250250
- name: Print network environment

native/balancers/mod_lbmethod_cluster.c

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static struct balancer_storage_method *balancer_storage = NULL;
3131
static struct domain_storage_method *domain_storage = NULL;
3232

3333
static int use_alias = 0; /* 1 : Compare Alias with server_name */
34+
static int use_nocanon = 0;
3435
static apr_time_t lbstatus_recalc_time =
3536
apr_time_from_sec(5); /* recalcul the lbstatus based on number of request in the time interval */
3637
static apr_time_t wait_for_remove = apr_time_from_sec(10); /* wait until that before removing a removed node */
@@ -142,16 +143,18 @@ static int lbmethod_cluster_trans(request_rec *r)
142143
{
143144
const char *balancer;
144145
void *sconf = r->server->module_config;
146+
const char *use_uri = r->uri;
145147
proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
148+
proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config, &proxy_module);
146149
proxy_vhost_table *vhost_table = read_vhost_table(r->pool, host_storage, 0);
147150
proxy_context_table *context_table = read_context_table(r->pool, context_storage, 0);
148151
proxy_balancer_table *balancer_table = read_balancer_table(r->pool, balancer_storage, 0);
149152
proxy_node_table *node_table = read_node_table(r->pool, node_storage, 0);
150153

151154
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server,
152-
"lbmethod_cluster_trans for %d %s %s uri: %s args: %s unparsed_uri: %s", r->proxyreq, r->filename,
155+
"lbmethod_cluster_trans: for %d %s %s uri: %s args: %s unparsed_uri: %s", r->proxyreq, r->filename,
153156
r->handler, r->uri, r->args, r->unparsed_uri);
154-
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "lbmethod_cluster_trans for %d", conf->balancers->nelts);
157+
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "lbmethod_cluster_trans: for %d", conf->balancers->nelts);
155158

156159
apr_table_setn(r->notes, "vhost-table", (char *)vhost_table);
157160
apr_table_setn(r->notes, "context-table", (char *)context_table);
@@ -163,29 +166,66 @@ static int lbmethod_cluster_trans(request_rec *r)
163166
balancer = get_context_host_balancer(r, vhost_table, context_table, node_table, use_alias);
164167
}
165168

166-
167169
if (balancer) {
170+
int i;
171+
int rv = HTTP_CONTINUE;
172+
struct proxy_alias *ent;
173+
/* short way - this location is reverse proxied? */
174+
if (dconf->alias) {
175+
if ((dconf->alias->flags & PROXYPASS_MAP_ENCODED) == 0) {
176+
rv = ap_proxy_trans_match(r, dconf->alias, dconf);
177+
if (rv != HTTP_CONTINUE) {
178+
ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
179+
"lbmethod_cluster_trans: ap_proxy_trans_match(dconf) matches or reject %s to %s %d",
180+
r->uri, r->filename, rv);
181+
return rv; /* Done */
182+
}
183+
}
184+
}
185+
186+
/* long way - walk the list of aliases, find a match */
187+
for (i = 0; i < conf->aliases->nelts; i++) {
188+
ent = &((struct proxy_alias *)conf->aliases->elts)[i];
189+
if ((ent->flags & PROXYPASS_MAP_ENCODED) == 0) {
190+
rv = ap_proxy_trans_match(r, ent, dconf);
191+
if (rv != HTTP_CONTINUE) {
192+
ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
193+
"lbmethod_cluster_trans: ap_proxy_trans_match(conf) matches or reject %s to %s %d",
194+
r->uri, r->filename, rv);
195+
return rv; /* Done */
196+
}
197+
}
198+
}
199+
}
168200

201+
/* Use proxy-nocanon if needed */
202+
if (use_nocanon) {
203+
apr_table_setn(r->notes, "proxy-nocanon", "1");
204+
use_uri = r->unparsed_uri;
205+
}
206+
207+
if (balancer) {
169208
/* It is safer to use r->uri */
170-
if (strncmp(r->uri, BALANCER_PREFIX, BALANCER_PREFIX_LENGTH)) {
171-
r->filename = apr_pstrcat(r->pool, ("proxy:" BALANCER_PREFIX), balancer, r->uri, NULL);
209+
if (strncmp(use_uri, BALANCER_PREFIX, BALANCER_PREFIX_LENGTH)) {
210+
r->filename = apr_pstrcat(r->pool, ("proxy:" BALANCER_PREFIX), balancer, use_uri, NULL);
172211
} else {
173-
r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
212+
r->filename = apr_pstrcat(r->pool, "proxy:", use_uri, NULL);
174213
}
175214
r->handler = "proxy-server";
176215
r->proxyreq = PROXYREQ_REVERSE;
177-
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "proxy_cluster_trans using %s uri: %s", balancer,
216+
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "lbmethod_cluster_trans: using %s uri: %s", balancer,
178217
r->filename);
179218
return OK; /* Mod_proxy will process it */
180219
}
181220

182221
ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, r->server,
183-
"proxy_cluster_trans DECLINED (no balancer) uri: %s unparsed_uri: %s", r->filename, r->unparsed_uri);
222+
"lbmethod_cluster_trans: DECLINED (no balancer) uri: %s unparsed_uri: %s", r->filename,
223+
r->unparsed_uri);
184224
return DECLINED;
185225
}
186226

187227
/*
188-
* Remove node that have beeen marked removed for more than 10 seconds.
228+
* Remove node that have been marked removed for more than 10 seconds.
189229
*/
190230
static void remove_removed_node(server_rec *s, apr_pool_t *pool, apr_time_t now, proxy_node_table *node_table)
191231
{
@@ -370,6 +410,20 @@ static int lbmethod_cluster_post_config(apr_pool_t *p, apr_pool_t *plog, apr_poo
370410
return OK;
371411
}
372412

413+
static const char *cmd_nocanon(cmd_parms *parms, void *mconfig, int on)
414+
{
415+
(void)parms;
416+
(void)mconfig;
417+
use_nocanon = on;
418+
419+
return NULL;
420+
}
421+
422+
static const command_rec lbmethod_cmds[] = {
423+
AP_INIT_FLAG("UseNocanon", cmd_nocanon, NULL, OR_ALL,
424+
"UseNocanon - When no ProxyPass or ProxyMatch for the URL, passes the URL path \"raw\" to the backend "
425+
"(Default: Off)")};
426+
373427
static void register_hooks(apr_pool_t *p)
374428
{
375429
static const char *const aszPre[] = {"mod_manager.c", "mod_rewrite.c", NULL};
@@ -388,7 +442,7 @@ AP_DECLARE_MODULE(lbmethod_cluster) = {
388442
NULL, /* merge per-directory config structures */
389443
NULL, /* create per-server config structure */
390444
NULL, /* merge per-server config structures */
391-
NULL, /* command apr_table_t */
445+
lbmethod_cmds, /* command apr_table_t */
392446
register_hooks, /* register hooks */
393447
AP_MODULE_FLAG_NONE /* flags */
394448
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
LoadModule proxy_module modules/mod_proxy.so
2+
LoadModule proxy_http_module modules/mod_proxy_http.so
3+
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
4+
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
5+
6+
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
7+
LoadModule manager_module modules/mod_manager.so
8+
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
9+
LoadModule watchdog_module modules/mod_watchdog.so
10+
11+
LogLevel info
12+
ServerName localhost
13+
ProxyPreserveHost On
14+
UseNocanon On
15+
16+
<IfModule manager_module>
17+
Listen 6666
18+
ManagerBalancerName mycluster
19+
20+
EnableWsTunnel
21+
WSUpgradeHeader websocket
22+
<VirtualHost *:6666>
23+
EnableMCMPReceive
24+
<Directory />
25+
Require ip 127.0.0.1
26+
Require ip ::1
27+
# This one is used in GH Actions
28+
Require ip 172.17.
29+
</Directory>
30+
<Location /mod_cluster_manager>
31+
SetHandler mod_cluster-manager
32+
Require ip 127.0.0.1
33+
Require ip ::1
34+
# This one is used in GH Actions
35+
Require ip 172.17.
36+
</Location>
37+
</VirtualHost>
38+
</IfModule>
39+
40+
<Proxy "balancer://mycluster">
41+
ProxySet growth=10
42+
ProxySet lbmethod=cluster
43+
</Proxy>

test/MODCLUSTER-640/testit.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ httpd_remove
88

99
# build httpd + mod_proxy_cluster
1010
rm -f nohup.out
11-
MPC_CONF=MODCLUSTER-640/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-640 httpd_start
11+
12+
MPC_CONF=${MPC_CONF:-MODCLUSTER-640/mod_proxy_cluster.conf}
13+
MPC_NAME=MODCLUSTER-640 httpd_start
1214

1315
# wait until httpd is started
1416
httpd_wait_until_ready || exit 1
@@ -39,7 +41,8 @@ if [ $? -eq 0 ]; then
3941
fi
4042

4143
# Test without UseNocanon On
42-
docker exec MODCLUSTER-640 sh -c "sed -i 's:UseNocanon On::' /usr/local/apache2/conf/mod_proxy_cluster.conf"
44+
docker exec MODCLUSTER-640 sh -c "sed -i 's:UseNocanon On::' /usr/local/apache2/conf/$(filename $MPC_CONF)"
45+
4346
docker exec MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart
4447

4548
# wait until the tomcats are back in mod_proxy_cluster tables
@@ -58,7 +61,7 @@ if [ $? -ne 0 ]; then
5861
fi
5962

6063
# Test for just a proxypass / nocanon
61-
docker exec MODCLUSTER-640 sh -c "echo 'ProxyPass / balancer://mycluster/ nocanon' >> /usr/local/apache2/conf/mod_proxy_cluster.conf"
64+
docker exec MODCLUSTER-640 sh -c "echo 'ProxyPass / balancer://mycluster/ nocanon' >> /usr/local/apache2/conf/$(filename $MPC_CONF)"
6265
docker exec MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart
6366

6467
# wait until the tomcats are back in mod_proxy_cluster tables

test/MODCLUSTER-734/testit.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ httpd_remove
88

99
# build httpd + mod_proxy_cluster
1010
rm -f nohup.out
11-
MPC_CONF=MODCLUSTER-734/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-734 httpd_start
11+
12+
MPC_CONF=${MPC_CONF:-MODCLUSTER-734/mod_proxy_cluster.conf}
13+
MPC_NAME=MODCLUSTER-734 httpd_start
1214

1315
# wait until httpd is started
1416
httpd_wait_until_ready || exit 1
@@ -28,6 +30,7 @@ docker cp MODCLUSTER-734/ROOT_OK tomcat2:/usr/local/tomcat/webapps/ROOT
2830
# after a while the health check will get the Under maintenance status.jsp
2931
# and mark the node not OK.
3032
sleep 15
33+
3134
curl -s http://localhost:6666/mod_cluster_manager | grep "Status: NOTOK"
3235
if [ $? -eq 0 ]; then
3336
echo "MODCLUSTER-734 Done!"

test/MODCLUSTER-736/testit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
httpd_remove
66
tomcat_all_remove
7+
78
MPC_NAME=MODCLUSTER-736 httpd_start
89

910
# Start a bunch ($1, or 6 if no argument is given) of tomcat
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
LoadModule proxy_module modules/mod_proxy.so
2+
LoadModule proxy_http_module modules/mod_proxy_http.so
3+
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
4+
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
5+
6+
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
7+
LoadModule manager_module modules/mod_manager.so
8+
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
9+
LoadModule watchdog_module modules/mod_watchdog.so
10+
11+
Maxnode 505
12+
Maxhost 1010
13+
Maxcontext 1100
14+
Listen 6666
15+
ManagerBalancerName mycluster
16+
ServerName localhost
17+
18+
<VirtualHost *:6666>
19+
EnableMCMPReceive
20+
<Directory />
21+
Require ip 127.0.0.1
22+
Require ip ::1
23+
# This one is used in GH Actions
24+
Require ip 172.17.
25+
</Directory>
26+
<Location /mod_cluster_manager>
27+
SetHandler mod_cluster-manager
28+
Require ip 127.0.0.1
29+
Require ip ::1
30+
# This one is used in GH Actions
31+
Require ip 172.17.
32+
</Location>
33+
</VirtualHost>
34+
35+
<Proxy "balancer://mycluster">
36+
ProxySet growth=10
37+
ProxySet lbmethod=cluster
38+
</Proxy>

test/MODCLUSTER-755/mod_proxy_cluster.conf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
55
LoadModule watchdog_module modules/mod_watchdog.so
66
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
77

8-
ProxyHCExpr in_maint {hc('body') !~ /Under maintenance/}
9-
ModProxyClusterHCTemplate hcmethod=GET hcexpr=in_maint hcuri=/status.jsp
10-
118
Maxnode 505
129
Maxhost 1010
1310
Maxcontext 1100

test/MODCLUSTER-755/testit.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
httpd_remove
1212
tomcat_all_remove
1313

14-
MPC_CONF=MODCLUSTER-755/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-755 httpd_start
14+
MPC_CONF=${MPC_CONF:-MODCLUSTER-755/mod_proxy_cluster.conf}
15+
MPC_NAME=MODCLUSTER-755 httpd_start
1516

1617
httpd_wait_until_ready
1718

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
LoadModule proxy_module modules/mod_proxy.so
2+
LoadModule proxy_http_module modules/mod_proxy_http.so
3+
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
4+
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
5+
6+
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
7+
LoadModule manager_module modules/mod_manager.so
8+
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
9+
LoadModule watchdog_module modules/mod_watchdog.so
10+
11+
Maxnode 505
12+
Maxhost 1010
13+
Maxcontext 1100
14+
Listen 6666
15+
ManagerBalancerName mycluster
16+
ServerName localhost
17+
18+
EnableWsTunnel
19+
WSUpgradeHeader websocket
20+
21+
<VirtualHost *:6666>
22+
EnableMCMPReceive
23+
<Directory />
24+
Require ip 127.0.0.1
25+
Require ip ::1
26+
# This one is used in GH Actions
27+
Require ip 172.17.
28+
</Directory>
29+
<Location /mod_cluster_manager>
30+
SetHandler mod_cluster-manager
31+
Require ip 127.0.0.1
32+
Require ip ::1
33+
# This one is used in GH Actions
34+
Require ip 172.17.
35+
</Location>
36+
</VirtualHost>
37+
38+
<Proxy "balancer://mycluster">
39+
ProxySet growth=10
40+
ProxySet lbmethod=cluster
41+
</Proxy>

0 commit comments

Comments
 (0)