2010/11/23 Bjvrn Ketelaars <[email protected]>:
> I'm running an application with a web-interface behind an Apache
> reverse proxy (from base). As this application is on the same host as
> Apache it is running on another port (8080 instead of 80).
> Unfortunately Apache sends back the wrong Host-Header. After carefully
> checking the CVS-log for a bit of inspiration I found that a similar
> problem was solved almost nine months ago [1]. When returning to an
> older revision (1.19.2.1) of proxy_http.c my problems were gone. After
> carefully looking at the code I think I have found a solution for the
> former problem as well as my problem.
>
> # diff -u proxy_http.c.orig proxy_http.c
> --- proxy_http.c.orig   Tue Nov 23 12:05:25 2010
> +++ proxy_http.c        Tue Nov 23 12:44:26 2010
> @@ -367,7 +367,7 @@
>                    AP_HOOK_DECLINE(DECLINED),
>                    &rc, r, f, desthost, destportstr, destportstr);
>         if (rc == DECLINED) {
> -           if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
> +           if (destportstr != NULL || destport != DEFAULT_HTTP_PORT)
>                ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF,
NULL);
>            else
>                ap_bvputs(f, "Host: ", desthost, CRLF, NULL);
>
> What do you think?
>
> [1]
http://www.openbsd.org/cgi-bin/cvsweb/src/usr.sbin/httpd/src/modules/proxy/pr
oxy_http.c
>

I believe I made a mistake:

destportstr != NULL => will be evaluated as true when a port is given.

destport != DEFAULT_HTTP_PORT => will ALWAYS be evaluated as false
because in line 118 (proxy_http.c) destport is set to
DEFAULT_HTTP_PORT and never changes. What really has to be compared is
the value of destportstr with destport (or DEFAULT_HTTP_PORT). So the
expression should be:

atoi(destportstr) != destport

New diff:

# diff -u proxy_http.c.orig proxy_http.c
--- proxy_http.c.orig   Tue Nov 23 12:05:25 2010
+++ proxy_http.c        Tue Nov 23 14:00:15 2010
@@ -367,7 +367,7 @@
                    AP_HOOK_DECLINE(DECLINED),
                    &rc, r, f, desthost, destportstr, destportstr);
         if (rc == DECLINED) {
-           if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
+           if (destportstr != NULL && atoi(destportstr) != destport)
                ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF,
NULL);
            else
                ap_bvputs(f, "Host: ", desthost, CRLF, NULL);

What do you think?

Reply via email to