--- modules/proxy/mod_proxy_http.c.orig Mon Aug 28 22:57:09 2006 +++ modules/proxy/mod_proxy_http.c Sun Feb 25 22:41:07 2007 @@ -720,6 +720,49 @@ r->server->server_hostname); } + /* Fix 'Destination' header value if we're running reverse proxy. + * This will unbreak at least DAV proxying. rea at codelabs dot ru. + */ + while (PROXYREQ_REVERSE == r->proxyreq && conf->aliases->nelts) { + unsigned int i, dport, l1, l2; + const char *dest = apr_table_get(r->headers_in, "Destination"); + char *ours, *proto, *destpath, *result; + struct proxy_alias *ent = (struct proxy_alias *)conf->aliases->elts; + + if (dest == NULL) + break; + + /* UGLY: maybe there is another way to obtain server base URL? */ + if (ap_proxy_conn_is_https(c)) { + proto = "https://"; + dport = DEFAULT_HTTPS_PORT; + } else { + proto = "http://"; + dport = DEFAULT_HTTP_PORT; + } + if (r->server->port != 0 && r->server->port != dport) { + ours = apr_pstrcat(p, proto, r->server->server_hostname, ":", + apr_ltoa(p, (long)r->server->port), NULL); + } else { + ours = apr_pstrcat(p, proto, r->server->server_hostname, NULL); + } + l1 = strlen(ours); + if (strncasecmp(dest, ours, l1) != 0) + break; + destpath = (char *)(&dest[l1]); + l1 = strlen(destpath); + + for (i = 0; i < conf->aliases->nelts; i++) { + l2 = strlen(ent[i].fake); + if (l1 >= l2 && strncmp(ent[i].fake, destpath, l2) == 0) { + result = apr_pstrcat(p, ent[i].real, &destpath[l2], NULL); + apr_table_set(r->headers_in, "Destination", result); + } + } + + break; + } + proxy_run_fixups(r); /* * Make a copy of the headers_in table before clearing the connection