Bug 55186 - useIPVHosts=true , incorrect to get Request.localName
Summary: useIPVHosts=true , incorrect to get Request.localName
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Connectors (show other bugs)
Version: 7.0.30
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
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.