costin 02/04/04 14:32:37 Modified: coyote/src/java/org/apache/coyote/tomcat3 CoyoteRequest.java coyote/src/java/org/apache/coyote/tomcat4 CoyoteProcessor.java Log: Remove the duplicated ( and protocol dependent ) Host: parsing code. I moved it to http11 ( and merged it a bit ). Please review ! Revision Changes Path 1.9 +10 -59 jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat3/CoyoteRequest.java Index: CoyoteRequest.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat3/CoyoteRequest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CoyoteRequest.java 1 Apr 2002 04:48:42 -0000 1.8 +++ CoyoteRequest.java 4 Apr 2002 22:32:37 -0000 1.9 @@ -80,9 +80,10 @@ * line and Mime headers between Coyote and Tomcat. * @Author Bill Barker */ -class CoyoteRequest extends Request { +public class CoyoteRequest extends org.apache.tomcat.core.Request { org.apache.coyote.Request coyoteRequest=null; + SSLSupport sslSupport=null; ByteChunk readChunk = new ByteChunk(); int pos=-1; @@ -197,57 +198,6 @@ } - /** Determine the local virual host and port from the <code>host</code> - * header. - */ - protected void parseHostHeader() { - MessageBytes hH=getMimeHeaders().getValue("host"); - serverPort = socket.getLocalPort(); - if (hH != null) { - ByteChunk valueBC = hH.getByteChunk(); - byte [] valueB = valueBC.getBytes(); - int valueL = valueBC.getLength(); - int valueS = valueBC.getStart(); - int colonPos = -1; - for( int i = 0; i < valueL; i++) { - byte b = valueB[i+valueS]; - if(b == ':') { - colonPos = i; - break; - } - } - if (colonPos > -1) { - serverNameMB.setBytes( valueB, valueS, colonPos); - int port = 0; - int mult = 1; - try { - for(int i = colonPos+1; i < valueL; i++) { - int charValue = HexUtils.DEC[(int)valueB[i+valueS]]; - if(charValue == -1) { - throw new NumberFormatException( - "Invalid port number: " + - valueB[i+valueS]); - } - port *= 10; - port += charValue; - } - serverPort = port; - }catch(NumberFormatException nfe){ - contextM.log("Port Parsing error", nfe); - } - }else { - serverNameMB.setBytes(valueB, valueS, valueL); - } - return; - } - if( localHost != null ) { - serverNameMB.setString( localHost ); - } - // default to localhost - and warn - // log("No server name, defaulting to localhost"); - serverNameMB.setString( getLocalHost() ); - } - // -------------------- override special methods public MessageBytes remoteAddr() { @@ -268,19 +218,20 @@ InetAddress localAddress = socket.getLocalAddress(); localHost = localAddress.getHostName(); return localHost; - } public MessageBytes serverName(){ - if(! serverNameMB.isNull()) return serverNameMB; - parseHostHeader(); - return serverNameMB; + // if(! serverNameMB.isNull()) return serverNameMB; + // parseHostHeader(); + return coyoteRequest.serverName(); } public int getServerPort(){ - if(serverPort!=-1) return serverPort; - parseHostHeader(); - return serverPort; + // if(serverPort!=-1) return serverPort; + //No need to delay execution - the host is certainly needed for + // mapping. + // parseHostHeader(); + return coyoteRequest.getServerPort(); } /** Define the SSL Support support instance for this socket. 1.20 +27 -94 jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java Index: CoyoteProcessor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- CoyoteProcessor.java 3 Apr 2002 15:57:11 -0000 1.19 +++ CoyoteProcessor.java 4 Apr 2002 22:32:37 -0000 1.20 @@ -1,6 +1,6 @@ -/* * $Header: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v 1.19 2002/04/03 15:57:11 remm Exp $ - * $Revision: 1.19 $ - * $Date: 2002/04/03 15:57:11 $ +/* * $Header: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v 1.20 2002/04/04 22:32:37 costin Exp $ + * $Revision: 1.20 $ + * $Date: 2002/04/04 22:32:37 $ * * ==================================================================== * @@ -120,7 +120,7 @@ * * @author Craig R. McClanahan * @author Remy Maucherat - * @version $Revision: 1.19 $ $Date: 2002/04/03 15:57:11 $ + * @version $Revision: 1.20 $ $Date: 2002/04/04 22:32:37 $ */ final class CoyoteProcessor @@ -142,8 +142,6 @@ this.connector = connector; this.debug = connector.getDebug(); this.id = id; - this.proxyName = connector.getProxyName(); - this.proxyPort = connector.getProxyPort(); this.request = (CoyoteRequest) connector.createRequest(); this.response = (CoyoteResponse) connector.createResponse(); this.request.setResponse(this.response); @@ -214,18 +212,6 @@ /** - * The proxy server name for our Connector. - */ - private String proxyName = null; - - - /** - * The proxy server port for our Connector. - */ - private int proxyPort = 0; - - - /** * The Coyote request object we will pass to our associated container. */ private CoyoteRequest request = null; @@ -293,12 +279,6 @@ private int status = Constants.PROCESSOR_IDLE; - /** - * Host name. - */ - private char[] hostName = new char[128]; - - // -------------------------------------------------------- Adapter Methods @@ -393,10 +373,30 @@ request.setAuthorization (req.getHeader(Constants.AUTHORIZATION_HEADER)); - if (proxyPort != 0) + // At this point the Host header has been processed. + // Override if the proxyPort/proxyHost are set + + // Replace the default port if we are in secure mode + if (req.getServerPort()==80 && connector.getScheme().equals("https")) { + req.setServerPort(443); + } + + String proxyName=connector.getProxyName(); + int proxyPort=connector.getProxyPort(); + + if (proxyPort != 0) { request.setServerPort(proxyPort); - else - request.setServerPort(serverPort); + req.setServerPort( proxyPort ); + } else { + request.setServerPort(req.getServerPort() ); + } + + if (proxyName != null) { + request.setServerName(proxyName); + req.serverName().setString( proxyName ); + } else { + request.setServerName( req.serverName().toString()); + } if (!normalize(req.decodedURI())) { res.setStatus(400); @@ -422,76 +422,9 @@ } } - parseHost(req); parseCookies(req); } - - - /** - * Parse host. - */ - protected void parseHost(Request req) - throws IOException { - - MessageBytes valueMB = req.getMimeHeaders().getValue("host"); - ByteChunk valueBC = null; - if (valueMB != null) { - valueBC = valueMB.getByteChunk(); - byte[] valueB = valueBC.getBytes(); - int valueL = valueBC.getLength(); - int valueS = valueBC.getStart(); - int colonPos = -1; - if (valueL > hostName.length) { - hostName = new char[valueL]; - } - for (int i = 0; i < valueL; i++) { - char b = (char) valueB[i + valueS]; - if (b == ':') { - colonPos = i; - break; - } - hostName[i] = b; - } - if (colonPos < 0) { - if (connector.getScheme().equals("http")) { - request.setServerPort(80); - } else if (connector.getScheme().equals("https")) { - request.setServerPort(443); - } - if (proxyName != null) { - request.setServerName(proxyName); - } else { - request.setServerName(new String(hostName, 0, valueL)); - } - } else { - if (proxyName != null) { - request.setServerName(proxyName); - } else { - request.setServerName(new String(hostName, 0, colonPos)); - } - if (proxyPort != 0) { - request.setServerPort(proxyPort); - } else { - int port = 0; - int mult = 1; - for (int i = valueL - 1; i > colonPos; i--) { - int charValue = HexUtils.DEC[(int) valueB[i + valueS]]; - if (charValue == -1) { - throw new IOException - (sm.getString - ("coyoteProcessor.parseHeaders.portNumber")); - } - port = port + (charValue * mult); - mult = 10 * mult; - } - request.setServerPort(port); - } - } - } - - } - /** * Parse session id in URL.
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>