Bug #1600
closedproxy-core.rewrite-request never works (error in mod_proxy_core.c)
Description
There is an error in mod_proxy_core.c, function proxy_get_request_header(). Function ends with code
if (i == p->conf.request_rewrites->used) { buffer_copy_string_buffer(sess->request_uri, con->request.uri); }
This condition is always true because there is a loop before it:
for (i = 0; i < p->conf.request_rewrites->used; i++) {
Rewrites will be done in loop, but then sess->request_uri will be restored back from con->request.uri. No rewrites will work in result.
Files
Updated by Anonymous over 16 years ago
see this error also in my setup... should be fixed asap i think, cause i need to have mod_proxy_core with ajp and rewriting (frontend for a tomcat installation) and there seems to be no possibility atm...
-- bb
Updated by Anonymous over 16 years ago
Replying to chernousov:
Rewrites will be done in loop, but then sess->request_uri will be restored back from con->request.uri. No rewrites will work in result.
This is incorrect. The rewrites of _scriptname and the like are taken care of here:
#!c proxy_encode_request_headers(srv, sess, con->recv);
However, I traced this through with gdb and realized the problem: you must handle _pathinfo before _scriptname because otherwise con->uri.path will be overwritten with whatever value you have set for _scriptname as can be seen here:
#!c } else if (buffer_is_equal_string(rw->header, CONST_STR_LEN("_scriptname"))) { int ret; if ((ret = pcre_replace(rw->regex, rw->replace, con->uri.path, p->replace_buf)) < 0) { switch (ret) { case PCRE_ERROR_NOMATCH: /* hmm, ok. no problem */ break; default: TRACE("oops, pcre_replace failed with: %d", ret); break; } } else { /* we matched, cool. */ buffer_copy_string_buffer(con->uri.path, p->replace_buf); } }
For now, the following should work around this bug (use appropriate regex of course):
proxy-core.rewrite-request = ( "_pathinfo" => ( "(.*)" => "$1"), "_scriptname" => ( ".*" => "/") )
-- osmaker+lighttpd
Updated by hoffie over 16 years ago
Everything except _uri worked fine for me. I'm not able to see how the code is supposed to work, I'm attaching a patch which makes _uri work for me, but I fear it might break something else. Any testing/review appreciated. :)
Updated by hoffie over 16 years ago
This one can be closed imo, as the patch was committed in r2146. Patch works still fine for me and did not break any other rewrite stuff. There were also some success reports in #lighttpd.
Updated by hoffie over 16 years ago
- Status changed from New to Fixed
- Resolution set to fixed
Also available in: Atom