On Thu, Jan 7, 2021 at 2:19 PM <yla...@apache.org> wrote: > > Author: ylavic > Date: Thu Jan 7 13:19:08 2021 > New Revision: 1885239 > > URL: http://svn.apache.org/viewvc?rev=1885239&view=rev > Log: > mod_proxy_wstunnel: leave Upgrade requests handling to mod_proxy_http. [snip] > +static int proxy_wstunnel_post_config(apr_pool_t *pconf, apr_pool_t *plog, > + apr_pool_t *ptemp, server_rec *s) > +{ > + fallback_to_mod_proxy_http = 0; > + if (ap_state_query(AP_SQ_MAIN_STATE) != AP_SQ_MS_CREATE_PRE_CONFIG) { > + apr_size_t i = 0; > + const module *mod; > + while ((mod = ap_loaded_modules[i++])) { > + if (strcmp(mod->name, "mod_proxy_http.c") == 0) { > + fallback_to_mod_proxy_http = 1; > + break; > + } > + } > + }
I wonder if, instead of the above loop to check whether mod_proxy_http is loaded, we'd better have an OPTIONAL_FN registered by mod_proxy_http and retrieved here. ISTR that we allow for different versions of (proxy) modules to run together, so if a user upgrades to the latest mod_proxy_wstunnel but keeps an older mod_proxy_http the above would not work.. Maybe I should apply the attached patch instead, or is it overkill? Cheers; Yann.
Index: include/ap_mmn.h =================================================================== --- include/ap_mmn.h (revision 1885238) +++ include/ap_mmn.h (working copy) @@ -664,6 +664,7 @@ * ap_proxy_read_input(). * 20200705.4 (2.5.1-dev) Add ap_get_status_line_ex() * 20201214.0 (2.5.1-dev) Axe struct core_net_rec + * 20201214.1 (2.5.1-dev) Add optional proxy_http_module_can_upgrade() */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -671,7 +672,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20201214 #endif -#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a Index: modules/proxy/mod_proxy.h =================================================================== --- modules/proxy/mod_proxy.h (revision 1885239) +++ modules/proxy/mod_proxy.h (working copy) @@ -1454,6 +1454,21 @@ PROXY_DECLARE(apr_status_t) ap_proxy_transfer_betw apr_off_t bsize, int flags); +/** + * Whether mod_proxy_http can switch/upgrade to another protocol (tunneling). + * @return 1 + * @note This optional function exists for 2.4 compatibility, should a + * mod_proxy_wstunnel able to fallback to proxy_http for upgrades be + * running with an older mod_proxy_http unable to handle it. The mere + * existence of the optional function is enough to determine whether + * mod_proxy_http handles upgrades, since the function is registered + * there and in the capable versions only, so there is actually no + * need to call the function (its return value is always true anyway), + * thus APR_RETRIEVE_OPTIONAL_FN(proxy_http_module_can_upgrade) != NULL + * is the relevant test. + */ +APR_DECLARE_OPTIONAL_FN(int, proxy_http_module_can_upgrade, (void)); + extern module PROXY_DECLARE_DATA proxy_module; #endif /*MOD_PROXY_H*/ Index: modules/proxy/mod_proxy_http.c =================================================================== --- modules/proxy/mod_proxy_http.c (revision 1885240) +++ modules/proxy/mod_proxy_http.c (working copy) @@ -2160,6 +2160,11 @@ static int proxy_http_post_config(apr_pool_t *pcon return OK; } +static int proxy_http_module_can_upgrade(void) +{ + return 1; +} + static void ap_proxy_http_register_hook(apr_pool_t *p) { ap_hook_post_config(proxy_http_post_config, NULL, NULL, APR_HOOK_MIDDLE); @@ -2166,6 +2171,7 @@ static void ap_proxy_http_register_hook(apr_pool_t proxy_hook_scheme_handler(proxy_http_handler, NULL, NULL, APR_HOOK_FIRST); proxy_hook_canon_handler(proxy_http_canon, NULL, NULL, APR_HOOK_FIRST); warn_rx = ap_pregcomp(p, "[0-9]{3}[ \t]+[^ \t]+[ \t]+\"[^\"]*\"([ \t]+\"([^\"]+)\")?", 0); + APR_REGISTER_OPTIONAL_FN(proxy_http_module_can_upgrade); } AP_DECLARE_MODULE(proxy_http) = { Index: modules/proxy/mod_proxy_wstunnel.c =================================================================== --- modules/proxy/mod_proxy_wstunnel.c (revision 1885239) +++ modules/proxy/mod_proxy_wstunnel.c (working copy) @@ -452,17 +452,8 @@ static const char * proxyws_set_asynch_delay(cmd_p static int proxy_wstunnel_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { - fallback_to_mod_proxy_http = 0; - if (ap_state_query(AP_SQ_MAIN_STATE) != AP_SQ_MS_CREATE_PRE_CONFIG) { - apr_size_t i = 0; - const module *mod; - while ((mod = ap_loaded_modules[i++])) { - if (strcmp(mod->name, "mod_proxy_http.c") == 0) { - fallback_to_mod_proxy_http = 1; - break; - } - } - } + fallback_to_mod_proxy_http = + APR_RETRIEVE_OPTIONAL_FN(proxy_http_module_can_upgrade) != NULL; return OK; }