the attached patch fixes some problems with the "compare the listener" part of
RewriteLocation 1, i.e. for situations where the Location header points to the
listener but with wrong port and/or protocol:
Currently the host part of the location header is resolved and then compared
to the listener address. No rewrite if they are not equal. If Listener Address
is set to 0.0.0.0 you're in trouble. The patch additionally compares the host
header from the request to the location's host.
Maybe we could even go one step further and remove the listener address
comparison altogether (the port comparison is still necessary). If the backend
sends a Location header pointing to the listener, it probably uses the host
header from the request. Or is there anything else it could derive the
external hostname from? The additional benefit would be that you can send
redirects to a different virtual host on the same listener without needing
Second (cosmetic) problem: the location header will not always include a port.
For these cases the default port numbers should be filled in. Otherwise the
port is 0 which is always different from the listener port, so the location
header will be changed even if it is not necessary. The "compare the back-end"
part of function need_redirect(...) already takes care of the default ports,
however it is overwritten by the memcpy at the beginning of "compare the
listener". So I just commented out the redundant memcpys.