Bug 55186

Summary: useIPVHosts=true , incorrect to get Request.localName
Product: Tomcat 7 Reporter: Roger Wang <jmwmj208>
Component: ConnectorsAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.0.30   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Roger Wang 2013-07-03 00:54:24 UTC
I configured useIPVHosts=true.
&set up two hosts :
<Host name="localhost" appBase="webapps" />
<Host name="www.jm.com" appBase="webapps2" />
&my pc has two ip: 10.10.4.48 and 192.168.56.1
&HOSTS file is:
~~~~~~~~~~~~~~~~~~
127.0.0.1 localhost
192.168.56.1 www.jm.com
~~~~~~~~~~~~~~~~~~
& the Host localhost has a app named examples. the other Host www.jm.com has a app named examples2.

start Tomcat,
visit http://www.jm.com:8080/examples2/test/ is ok. but i changed to visit 
http://localhost:8080/examples/test without restart tc, it didn't work.
then i traced the codes,i found that :
~~~~~~~~~~~~~~~~~~~~~~~
        if (connector.getUseIPVHosts()) {
            serverName = req.localName(); //line 624
            if (serverName.isNull()) {
                // well, they did ask for it
                res.action(ActionCode.REQ_LOCAL_NAME_ATTRIBUTE, null);
            }
        } else {
            serverName = req.serverName();
        }
~~~~~~~~~~~~~~~~~~~~~~~
at line 624 the value of serverName is still "www.jm.com" . it will still find  the Host www.jm.com to handle with the request.but this host doesn't have the examples app, so it can't make it.

if i annotate the "if condition" , it works.
~~~~~~~~~~~~~~~~~~~~~
if (connector.getUseIPVHosts()) {
            serverName = req.localName(); //line 624
            //if (serverName.isNull()) { 
//annotate if , execute action every time.
                // well, they did ask for it
                res.action(ActionCode.REQ_LOCAL_NAME_ATTRIBUTE, null);
            //}
        } else {
            serverName = req.serverName();
        }
~~~~~~~~~~~~~~~~~~~~
Comment 1 Mark Thomas 2013-07-05 13:39:35 UTC
Thanks for the report. This has been fixed in trunk and 7.0.x and will be included in 7.0.43 onwards.