Dear all i've got a strange behaviour in my custom module:
it seems that if the set filename overlaps the requested uri ths final uri passed to mod_proxy is wrong, or has some added strange characters. some information: * the module is activated only when the requested uri contains the string "/files/anteprima" * the module just redirect the request to mod_proxy changing the request from "/files/anteprima" to "nocachedfiles/anteprima/" * i know all is hardcoded here but is just to reproduce the problem My module is configured in a vhost and related to a specific Location: <Location /data> SetHandler kcache </Location> if i make a request to this module, for example: http://kcache.foo.com:19007/data/_www.foo.com/files/anteprima/whatyouwant Looking at the code it should be redirected to: proxy:http://www.foooo.com/nocachedfiles/anteprima/12345 but looking at apache logs i see: [Tue Aug 21 13:27:01 2012] [debug] mod_proxy_http.c(56): proxy: HTTP: canonicalising URL //www.foooo.com/nocachedfiles/anteprima/12345 dJ\x98\x01\x7f [Tue Aug 21 13:27:01 2012] [debug] proxy_util.c(1515): [client 127.0.0.1] proxy: *: found forward proxy worker for http://www.foooo.com/nocachedfiles/anteprima/12345 dJ\x98\x01\x7f [Tue Aug 21 13:27:01 2012] [debug] mod_proxy_http.c(1973): proxy: HTTP: serving URL http://www.foooo.com/nocachedfiles/anteprima/12345 dJ\x98\x01\x7f [Tue Aug 21 13:27:01 2012] [debug] proxy_util.c(2067): proxy: connecting http://www.foooo.com/nocachedfiles/anteprima/12345 dJ\x98\x01\x7f to www.foooo.com:80 You can see some "garbage" at the end of the string. I've tried to investigate a lot on in, but i'm not able to figure it out... notice that if you change the length of the newurl string, or if you change it from: "proxy:http://www.foooo.com/nocachedfiles/anteprima/12345"; to "proxy:http://www.foooo.com/nocachedfiles2/anteprima/12345"; The module tries correctly to load http://www.foooo.com/nocachedfiles2/anteprima/12345 withoud any garbage at the end. It seems to be a combination of overlaps of the requested uri, the destination file and their length... here there is the exact code to reproduce it: One last thing : is not yet clear to me if is correct to put this kind of redirection in ap_hook_translate_name or if i have to use another type of hook, by the way if you use a ap_hook_handler in the same conditions you get an http contatenated at the end of your filename: [Tue Aug 21 13:37:02 2012] [debug] proxy_util.c(1515): [client 127.0.0.1] proxy: *: found forward proxy worker for http://www.foooo.com/nocachedfiles/anteprima/12345http Any idea? Thanks to all in advance /************************************************/ #include <httpd.h> #include <http_protocol.h> #include <http_config.h> static void register_hooks(apr_pool_t *pool); module AP_MODULE_DECLARE_DATA kcache_module = { STANDARD20_MODULE_STUFF, NULL, NULL, NULL, NULL, NULL, register_hooks }; static int kcache_handler_translate(request_rec* r) { if (r->method_number != M_GET && r->method_number != M_POST){ return HTTP_METHOD_NOT_ALLOWED; } if( strstr(r->unparsed_uri, "/files/anteprima")==NULL){ return DECLINED; } char *newurl = "proxy:http://www.foooo.com/nocachedfiles/anteprima/12345"; r->filename = apr_pcalloc(r->pool,strlen(newurl)); strcpy(r->filename,newurl); r->proxyreq = PROXYREQ_PROXY; r->handler = "proxy-server"; return DECLINED; } static void register_hooks(apr_pool_t* pool) { static const char *succ[] = {"mod_proxy.c","mod_alias.c","mod_userdir.c", NULL}; ap_hook_translate_name(kcache_handler_translate, NULL, succ, APR_HOOK_MIDDLE); } /***********************************************/ -- /*************/ nik600 http://www.kumbe.it