Re: forward request with proxy_http in custom module
Ok, it wasn't clear to me to return DECLINED to look for other handlers, and also wasn't clear the possibility to specify an order. Now it works, thanks. On Fri, Aug 17, 2012 at 4:42 PM, Sorin Manolache wrote: > On 2012-08-17 16:25, nik600 wrote: >> >> Dear all >> >> i'm trying to code a custom module that will implement some logic this >> is the concept of the module: >> >> * >> >> /* >> * some stuff... >> */ >> if(condition){ >> >> /*return a custom result*/ >> >> return OK; >> >> }else{ >> /*forward the request to another server*/ >> >> r->filename = "proxy:http://www.google.it/";; >> r->proxyreq = PROXYREQ_PROXY; >> r->handler = "proxy-server"; >> >> return OK; >> } >> * >> >> But it seems that when i go into the else condition the proxy request >> isn't handled. >> >> proxy and proxy_http are enabled and correctly working. >> >> Is this code correct to forward a request and make my module working >> as a proxy_http ? > > > > Try > > if (condition) { > ... > return OK; > } else { > return DECLINED; > } > > and make sure your handler runs before mod_proxy's: > > static const char *succ[] = {"mod_proxy.c", NULL}; > ap_hook_handler(&your_handler, NULL, succ, APR_HOOK_MIDDLE); > > Then put a ProxyPass in your conf: > > >ProxyPass http://www.google.it/ keepalive=On > > > Also make sure you do not check on r->handler. Even if you set "SetHandler > your_handler", ProxyPass will overwrite it with "proxy-server". > > > Sorin > >> >> Thanks in advance >> > -- /*/ nik600 http://www.kumbe.it
Re: forward request with proxy_http in custom module
On 2012-08-17 16:25, nik600 wrote: Dear all i'm trying to code a custom module that will implement some logic this is the concept of the module: * /* * some stuff... */ if(condition){ /*return a custom result*/ return OK; }else{ /*forward the request to another server*/ r->filename = "proxy:http://www.google.it/";; r->proxyreq = PROXYREQ_PROXY; r->handler = "proxy-server"; return OK; } * But it seems that when i go into the else condition the proxy request isn't handled. proxy and proxy_http are enabled and correctly working. Is this code correct to forward a request and make my module working as a proxy_http ? Try if (condition) { ... return OK; } else { return DECLINED; } and make sure your handler runs before mod_proxy's: static const char *succ[] = {"mod_proxy.c", NULL}; ap_hook_handler(&your_handler, NULL, succ, APR_HOOK_MIDDLE); Then put a ProxyPass in your conf: ProxyPass http://www.google.it/ keepalive=On Also make sure you do not check on r->handler. Even if you set "SetHandler your_handler", ProxyPass will overwrite it with "proxy-server". Sorin Thanks in advance
Re: forward request with proxy_http in custom module
On Fri, Aug 17, 2012 at 10:25 AM, nik600 wrote: > Dear all > > i'm trying to code a custom module that will implement some logic this > is the concept of the module: > > * > > /* > * some stuff... > */ > if(condition){ > > /*return a custom result*/ > > return OK; > > }else{ > /*forward the request to another server*/ > > r->filename = "proxy:http://www.google.it/";; > r->proxyreq = PROXYREQ_PROXY; > r->handler = "proxy-server"; > > return OK; > } You should probably do his in an earlier phase. In a handler, you couldn't return OK and still expect the proxy to run right? See how mod_rewrite does it in translate_name/fixups
forward request with proxy_http in custom module
Dear all i'm trying to code a custom module that will implement some logic this is the concept of the module: * /* * some stuff... */ if(condition){ /*return a custom result*/ return OK; }else{ /*forward the request to another server*/ r->filename = "proxy:http://www.google.it/";; r->proxyreq = PROXYREQ_PROXY; r->handler = "proxy-server"; return OK; } * But it seems that when i go into the else condition the proxy request isn't handled. proxy and proxy_http are enabled and correctly working. Is this code correct to forward a request and make my module working as a proxy_http ? Thanks in advance -- /*/ nik600