Project

General

Profile

Actions

Bug #1600

closed

proxy-core.rewrite-request never works (error in mod_proxy_core.c)

Added by chernousov almost 17 years ago. Updated over 16 years ago.

Status:
Fixed
Priority:
Urgent
Category:
mod_proxy_core
Target version:
ASK QUESTIONS IN Forums:

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


Related issues 1 (0 open1 closed)

Has duplicate Bug #1206: mod_proxy_core fails to rewrite proxy URL [fixed => ADD TO TRUNK!]FixedstbuehlerActions
Actions #1

Updated by Anonymous almost 17 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

Actions #2

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

Actions #3

Updated by chernousov over 16 years ago

I'm talking about rewriting of _uri.

Actions #4

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. :)

Actions #5

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.

Actions #6

Updated by hoffie over 16 years ago

  • Status changed from New to Fixed
  • Resolution set to fixed
Actions

Also available in: Atom