Bug 55186 - useIPVHosts=true , incorrect to get Request.localName
useIPVHosts=true , incorrect to get Request.localName
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Connectors
7.0.30
PC All
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2013-07-03 00:54 UTC by Roger Wang
Modified: 2013-07-05 13:39 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.