@@ -31,6 +31,7 @@ static struct balancer_storage_method *balancer_storage = NULL;
3131static struct domain_storage_method * domain_storage = NULL ;
3232
3333static int use_alias = 0 ; /* 1 : Compare Alias with server_name */
34+ static int use_nocanon = 0 ;
3435static apr_time_t lbstatus_recalc_time =
3536 apr_time_from_sec (5 ); /* recalcul the lbstatus based on number of request in the time interval */
3637static 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 */
190230static 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+
373427static 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};
0 commit comments