You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by be...@stardivision.de on 1999/11/09 19:35:16 UTC

HTTPServletRequest.getServerName() always returns "localhost" !

Hi there !

HTTPServletRequest.getServerName() always returns "localhost" 

on standalone Web Server and ajp22Connector

Bugfix request for 
jakarta-tomcat/src/share/org/apache/http/HttpConnectionHandler.java

just copied in some code from ../../server/ConnectionHandler.java to 
fix it,
fix for other handlers still needed.

Can some Committer have a look at this and check in something like the 
following (cvs diff) or have a look for a better solution ?

Cordially,
Bernd Eilers

Index: HttpConnectionHandler.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/service/ht
tp/HttpConnectionHandler.java,v
retrieving revision 1.6
diff -r1.6 HttpConnectionHandler.java
124a125,144
> 		String hostHeader = request.getHeader("host");
> 
> 		if (hostHeader != null) {
> 		    // shave off the port part of the host header if
> 		    // it exists
> 
> 		    int i = hostHeader.indexOf(':');
> 
> 		    if (i > -1) {
> 			hostHeader = hostHeader.substring(0,i);
> 		    }
> 
> 		    reqA.setServerName(hostHeader);
> 		} else {
> 		    // XXX
> 		    // we need a better solution here
> 		    InetAddress localAddress = socket.getLocalAddress();
> 		    reqA.setServerName(localAddress.getHostName());
> 		}
>