Author: markt Date: Sun Jun 19 21:33:55 2011 New Revision: 1137451 URL: http://svn.apache.org/viewvc?rev=1137451&view=rev Log: Pull up prepareRequest()
Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1137451&r1=1137450&r2=1137451&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Sun Jun 19 21:33:55 2011 @@ -17,6 +17,7 @@ package org.apache.coyote.http11; import java.io.IOException; +import java.util.Locale; import java.util.StringTokenizer; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; @@ -767,6 +768,209 @@ public abstract class AbstractHttp11Proc /** + * After reading the request headers, we have to setup the request filters. + */ + protected void prepareRequest() { + + http11 = true; + http09 = false; + contentDelimitation = false; + expectation = false; + if (endpoint.isSSLEnabled()) { + request.scheme().setString("https"); + } + MessageBytes protocolMB = request.protocol(); + if (protocolMB.equals(Constants.HTTP_11)) { + http11 = true; + protocolMB.setString(Constants.HTTP_11); + } else if (protocolMB.equals(Constants.HTTP_10)) { + http11 = false; + keepAlive = false; + protocolMB.setString(Constants.HTTP_10); + } else if (protocolMB.equals("")) { + // HTTP/0.9 + http09 = true; + http11 = false; + keepAlive = false; + } else { + // Unsupported protocol + http11 = false; + error = true; + // Send 505; Unsupported HTTP version + if (getLog().isDebugEnabled()) { + getLog().debug(sm.getString("http11processor.request.prepare")+ + " Unsupported HTTP version \""+protocolMB+"\""); + } + response.setStatus(505); + adapter.log(request, response, 0); + } + + MessageBytes methodMB = request.method(); + if (methodMB.equals(Constants.GET)) { + methodMB.setString(Constants.GET); + } else if (methodMB.equals(Constants.POST)) { + methodMB.setString(Constants.POST); + } + + MimeHeaders headers = request.getMimeHeaders(); + + // Check connection header + MessageBytes connectionValueMB = headers.getValue("connection"); + if (connectionValueMB != null) { + ByteChunk connectionValueBC = connectionValueMB.getByteChunk(); + if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) { + keepAlive = false; + } else if (findBytes(connectionValueBC, + Constants.KEEPALIVE_BYTES) != -1) { + keepAlive = true; + } + } + + MessageBytes expectMB = null; + if (http11) + expectMB = headers.getValue("expect"); + if ((expectMB != null) + && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) { + getInputBuffer().setSwallowInput(false); + expectation = true; + } + + // Check user-agent header + if ((restrictedUserAgents != null) && ((http11) || (keepAlive))) { + MessageBytes userAgentValueMB = headers.getValue("user-agent"); + // Check in the restricted list, and adjust the http11 + // and keepAlive flags accordingly + if(userAgentValueMB != null) { + String userAgentValue = userAgentValueMB.toString(); + if (restrictedUserAgents != null && + restrictedUserAgents.matcher(userAgentValue).matches()) { + http11 = false; + keepAlive = false; + } + } + } + + // Check for a full URI (including protocol://host:port/) + ByteChunk uriBC = request.requestURI().getByteChunk(); + if (uriBC.startsWithIgnoreCase("http", 0)) { + + int pos = uriBC.indexOf("://", 0, 3, 4); + int uriBCStart = uriBC.getStart(); + int slashPos = -1; + if (pos != -1) { + byte[] uriB = uriBC.getBytes(); + slashPos = uriBC.indexOf('/', pos + 3); + if (slashPos == -1) { + slashPos = uriBC.getLength(); + // Set URI as "/" + request.requestURI().setBytes + (uriB, uriBCStart + pos + 1, 1); + } else { + request.requestURI().setBytes + (uriB, uriBCStart + slashPos, + uriBC.getLength() - slashPos); + } + MessageBytes hostMB = headers.setValue("host"); + hostMB.setBytes(uriB, uriBCStart + pos + 3, + slashPos - pos - 3); + } + + } + + // Input filter setup + InputFilter[] inputFilters = getInputBuffer().getFilters(); + + // Parse transfer-encoding header + MessageBytes transferEncodingValueMB = null; + if (http11) + transferEncodingValueMB = headers.getValue("transfer-encoding"); + if (transferEncodingValueMB != null) { + String transferEncodingValue = transferEncodingValueMB.toString(); + // Parse the comma separated list. "identity" codings are ignored + int startPos = 0; + int commaPos = transferEncodingValue.indexOf(','); + String encodingName = null; + while (commaPos != -1) { + encodingName = transferEncodingValue.substring + (startPos, commaPos).toLowerCase(Locale.ENGLISH).trim(); + if (!addInputFilter(inputFilters, encodingName)) { + // Unsupported transfer encoding + error = true; + // 501 - Unimplemented + response.setStatus(501); + adapter.log(request, response, 0); + } + startPos = commaPos + 1; + commaPos = transferEncodingValue.indexOf(',', startPos); + } + encodingName = transferEncodingValue.substring(startPos) + .toLowerCase(Locale.ENGLISH).trim(); + if (!addInputFilter(inputFilters, encodingName)) { + // Unsupported transfer encoding + error = true; + // 501 - Unimplemented + if (getLog().isDebugEnabled()) { + getLog().debug(sm.getString("http11processor.request.prepare")+ + " Unsupported transfer encoding \""+encodingName+"\""); + } + response.setStatus(501); + adapter.log(request, response, 0); + } + } + + // Parse content-length header + long contentLength = request.getContentLengthLong(); + if (contentLength >= 0 && !contentDelimitation) { + getInputBuffer().addActiveFilter + (inputFilters[Constants.IDENTITY_FILTER]); + contentDelimitation = true; + } + + MessageBytes valueMB = headers.getValue("host"); + + // Check host header + if (http11 && (valueMB == null)) { + error = true; + // 400 - Bad request + if (getLog().isDebugEnabled()) { + getLog().debug(sm.getString("http11processor.request.prepare")+ + " host header missing"); + } + response.setStatus(400); + adapter.log(request, response, 0); + } + + parseHost(valueMB); + + if (!contentDelimitation) { + // If there's no content length + // (broken HTTP/1.0 or HTTP/1.1), assume + // the client is not broken and didn't send a body + getInputBuffer().addActiveFilter + (inputFilters[Constants.VOID_FILTER]); + contentDelimitation = true; + } + + // Advertise sendfile support through a request attribute + if (endpoint.getUseSendfile()) { + request.setAttribute("org.apache.tomcat.sendfile.support", + Boolean.TRUE); + } + + // Advertise comet support through a request attribute + if (endpoint.getUseComet()) { + request.setAttribute("org.apache.tomcat.comet.support", + Boolean.TRUE); + } + // Advertise comet timeout support + if (endpoint.getUseCometTimeout()) { + request.setAttribute("org.apache.tomcat.comet.timeout.support", + Boolean.TRUE); + } + } + + + /** * When committing the response, we have to validate the set of headers, as * well as setup the response filters. */ Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1137451&r1=1137450&r2=1137451&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Sun Jun 19 21:33:55 2011 @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.Locale; import org.apache.coyote.ActionCode; import org.apache.coyote.RequestInfo; @@ -35,10 +34,7 @@ import org.apache.tomcat.jni.SSLSocket; import org.apache.tomcat.jni.Sockaddr; import org.apache.tomcat.jni.Socket; import org.apache.tomcat.util.ExceptionUtils; -import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.buf.HexUtils; -import org.apache.tomcat.util.buf.MessageBytes; -import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.AprEndpoint; import org.apache.tomcat.util.net.SSLSupport; @@ -628,188 +624,6 @@ public class Http11AprProcessor extends // ------------------------------------------------------ Protected Methods - /** - * After reading the request headers, we have to setup the request filters. - */ - protected void prepareRequest() { - - http11 = true; - http09 = false; - contentDelimitation = false; - expectation = false; - if (endpoint.isSSLEnabled()) { - request.scheme().setString("https"); - } - MessageBytes protocolMB = request.protocol(); - if (protocolMB.equals(Constants.HTTP_11)) { - http11 = true; - protocolMB.setString(Constants.HTTP_11); - } else if (protocolMB.equals(Constants.HTTP_10)) { - http11 = false; - keepAlive = false; - protocolMB.setString(Constants.HTTP_10); - } else if (protocolMB.equals("")) { - // HTTP/0.9 - http09 = true; - http11 = false; - keepAlive = false; - } else { - // Unsupported protocol - http11 = false; - error = true; - // Send 505; Unsupported HTTP version - response.setStatus(505); - adapter.log(request, response, 0); - } - - MessageBytes methodMB = request.method(); - if (methodMB.equals(Constants.GET)) { - methodMB.setString(Constants.GET); - } else if (methodMB.equals(Constants.POST)) { - methodMB.setString(Constants.POST); - } - - MimeHeaders headers = request.getMimeHeaders(); - - // Check connection header - MessageBytes connectionValueMB = headers.getValue("connection"); - if (connectionValueMB != null) { - ByteChunk connectionValueBC = connectionValueMB.getByteChunk(); - if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) { - keepAlive = false; - } else if (findBytes(connectionValueBC, - Constants.KEEPALIVE_BYTES) != -1) { - keepAlive = true; - } - } - - MessageBytes expectMB = null; - if (http11) - expectMB = headers.getValue("expect"); - if ((expectMB != null) - && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) { - inputBuffer.setSwallowInput(false); - expectation = true; - } - - // Check user-agent header - if ((restrictedUserAgents != null) && ((http11) || (keepAlive))) { - MessageBytes userAgentValueMB = headers.getValue("user-agent"); - // Check in the restricted list, and adjust the http11 - // and keepAlive flags accordingly - if(userAgentValueMB != null) { - String userAgentValue = userAgentValueMB.toString(); - if (restrictedUserAgents != null && - restrictedUserAgents.matcher(userAgentValue).matches()) { - http11 = false; - keepAlive = false; - } - } - } - - // Check for a full URI (including protocol://host:port/) - ByteChunk uriBC = request.requestURI().getByteChunk(); - if (uriBC.startsWithIgnoreCase("http", 0)) { - - int pos = uriBC.indexOf("://", 0, 3, 4); - int uriBCStart = uriBC.getStart(); - int slashPos = -1; - if (pos != -1) { - byte[] uriB = uriBC.getBytes(); - slashPos = uriBC.indexOf('/', pos + 3); - if (slashPos == -1) { - slashPos = uriBC.getLength(); - // Set URI as "/" - request.requestURI().setBytes - (uriB, uriBCStart + pos + 1, 1); - } else { - request.requestURI().setBytes - (uriB, uriBCStart + slashPos, - uriBC.getLength() - slashPos); - } - MessageBytes hostMB = headers.setValue("host"); - hostMB.setBytes(uriB, uriBCStart + pos + 3, - slashPos - pos - 3); - } - - } - - // Input filter setup - InputFilter[] inputFilters = inputBuffer.getFilters(); - - // Parse transfer-encoding header - MessageBytes transferEncodingValueMB = null; - if (http11) - transferEncodingValueMB = headers.getValue("transfer-encoding"); - if (transferEncodingValueMB != null) { - String transferEncodingValue = transferEncodingValueMB.toString(); - // Parse the comma separated list. "identity" codings are ignored - int startPos = 0; - int commaPos = transferEncodingValue.indexOf(','); - String encodingName = null; - while (commaPos != -1) { - encodingName = transferEncodingValue.substring - (startPos, commaPos).toLowerCase(Locale.ENGLISH).trim(); - if (!addInputFilter(inputFilters, encodingName)) { - // Unsupported transfer encoding - error = true; - // 501 - Unimplemented - response.setStatus(501); - adapter.log(request, response, 0); - } - startPos = commaPos + 1; - commaPos = transferEncodingValue.indexOf(',', startPos); - } - encodingName = transferEncodingValue.substring(startPos) - .toLowerCase(Locale.ENGLISH).trim(); - if (!addInputFilter(inputFilters, encodingName)) { - // Unsupported transfer encoding - error = true; - // 501 - Unimplemented - response.setStatus(501); - adapter.log(request, response, 0); - } - } - - // Parse content-length header - long contentLength = request.getContentLengthLong(); - if (contentLength >= 0 && !contentDelimitation) { - inputBuffer.addActiveFilter - (inputFilters[Constants.IDENTITY_FILTER]); - contentDelimitation = true; - } - - MessageBytes valueMB = headers.getValue("host"); - - // Check host header - if (http11 && (valueMB == null)) { - error = true; - // 400 - Bad request - response.setStatus(400); - adapter.log(request, response, 0); - } - - parseHost(valueMB); - - if (!contentDelimitation) { - // If there's no content length - // (broken HTTP/1.0 or HTTP/1.1), assume - // the client is not broken and didn't send a body - inputBuffer.addActiveFilter - (inputFilters[Constants.VOID_FILTER]); - contentDelimitation = true; - } - - // Advertise sendfile support through a request attribute - if (endpoint.getUseSendfile()) { - request.setAttribute("org.apache.tomcat.sendfile.support", Boolean.TRUE); - } - // Advertise comet support through a request attribute - request.setAttribute("org.apache.tomcat.comet.support", Boolean.TRUE); - - } - - @Override protected boolean prepareSendfile(OutputFilter[] outputFilters) { String fileName = (String) request.getAttribute( Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1137451&r1=1137450&r2=1137451&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Sun Jun 19 21:33:55 2011 @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.net.InetAddress; import java.nio.channels.SelectionKey; -import java.util.Locale; import javax.net.ssl.SSLEngine; @@ -33,8 +32,6 @@ import org.apache.tomcat.util.ExceptionU import org.apache.tomcat.util.buf.Ascii; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.buf.HexUtils; -import org.apache.tomcat.util.buf.MessageBytes; -import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.NioChannel; import org.apache.tomcat.util.net.NioEndpoint; @@ -672,209 +669,6 @@ public class Http11NioProcessor extends // ------------------------------------------------------ Protected Methods - /** - * After reading the request headers, we have to setup the request filters. - */ - protected void prepareRequest() { - - http11 = true; - http09 = false; - contentDelimitation = false; - expectation = false; - if (endpoint.isSSLEnabled()) { - request.scheme().setString("https"); - } - MessageBytes protocolMB = request.protocol(); - if (protocolMB.equals(Constants.HTTP_11)) { - http11 = true; - protocolMB.setString(Constants.HTTP_11); - } else if (protocolMB.equals(Constants.HTTP_10)) { - http11 = false; - keepAlive = false; - protocolMB.setString(Constants.HTTP_10); - } else if (protocolMB.equals("")) { - // HTTP/0.9 - http09 = true; - http11 = false; - keepAlive = false; - } else { - // Unsupported protocol - http11 = false; - error = true; - // Send 505; Unsupported HTTP version - if (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.prepare")+ - " Unsupported HTTP version \""+protocolMB+"\""); - } - response.setStatus(505); - adapter.log(request, response, 0); - } - - MessageBytes methodMB = request.method(); - if (methodMB.equals(Constants.GET)) { - methodMB.setString(Constants.GET); - } else if (methodMB.equals(Constants.POST)) { - methodMB.setString(Constants.POST); - } - - MimeHeaders headers = request.getMimeHeaders(); - - // Check connection header - MessageBytes connectionValueMB = headers.getValue("connection"); - if (connectionValueMB != null) { - ByteChunk connectionValueBC = connectionValueMB.getByteChunk(); - if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) { - keepAlive = false; - } else if (findBytes(connectionValueBC, - Constants.KEEPALIVE_BYTES) != -1) { - keepAlive = true; - } - } - - MessageBytes expectMB = null; - if (http11) - expectMB = headers.getValue("expect"); - if ((expectMB != null) - && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) { - inputBuffer.setSwallowInput(false); - expectation = true; - } - - // Check user-agent header - if ((restrictedUserAgents != null) && ((http11) || (keepAlive))) { - MessageBytes userAgentValueMB = headers.getValue("user-agent"); - // Check in the restricted list, and adjust the http11 - // and keepAlive flags accordingly - if(userAgentValueMB != null) { - String userAgentValue = userAgentValueMB.toString(); - if (restrictedUserAgents != null && - restrictedUserAgents.matcher(userAgentValue).matches()) { - http11 = false; - keepAlive = false; - } - } - } - - // Check for a full URI (including protocol://host:port/) - ByteChunk uriBC = request.requestURI().getByteChunk(); - if (uriBC.startsWithIgnoreCase("http", 0)) { - - int pos = uriBC.indexOf("://", 0, 3, 4); - int uriBCStart = uriBC.getStart(); - int slashPos = -1; - if (pos != -1) { - byte[] uriB = uriBC.getBytes(); - slashPos = uriBC.indexOf('/', pos + 3); - if (slashPos == -1) { - slashPos = uriBC.getLength(); - // Set URI as "/" - request.requestURI().setBytes - (uriB, uriBCStart + pos + 1, 1); - } else { - request.requestURI().setBytes - (uriB, uriBCStart + slashPos, - uriBC.getLength() - slashPos); - } - MessageBytes hostMB = headers.setValue("host"); - hostMB.setBytes(uriB, uriBCStart + pos + 3, - slashPos - pos - 3); - } - - } - - // Input filter setup - InputFilter[] inputFilters = inputBuffer.getFilters(); - - // Parse transfer-encoding header - MessageBytes transferEncodingValueMB = null; - if (http11) - transferEncodingValueMB = headers.getValue("transfer-encoding"); - if (transferEncodingValueMB != null) { - String transferEncodingValue = transferEncodingValueMB.toString(); - // Parse the comma separated list. "identity" codings are ignored - int startPos = 0; - int commaPos = transferEncodingValue.indexOf(','); - String encodingName = null; - while (commaPos != -1) { - encodingName = transferEncodingValue.substring - (startPos, commaPos).toLowerCase(Locale.ENGLISH).trim(); - if (!addInputFilter(inputFilters, encodingName)) { - // Unsupported transfer encoding - error = true; - // 501 - Unimplemented - response.setStatus(501); - adapter.log(request, response, 0); - } - startPos = commaPos + 1; - commaPos = transferEncodingValue.indexOf(',', startPos); - } - encodingName = transferEncodingValue.substring(startPos) - .toLowerCase(Locale.ENGLISH).trim(); - if (!addInputFilter(inputFilters, encodingName)) { - // Unsupported transfer encoding - error = true; - // 501 - Unimplemented - if (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.prepare")+ - " Unsupported transfer encoding \""+encodingName+"\""); - } - response.setStatus(501); - adapter.log(request, response, 0); - } - } - - // Parse content-length header - long contentLength = request.getContentLengthLong(); - if (contentLength >= 0 && !contentDelimitation) { - inputBuffer.addActiveFilter - (inputFilters[Constants.IDENTITY_FILTER]); - contentDelimitation = true; - } - - MessageBytes valueMB = headers.getValue("host"); - - // Check host header - if (http11 && (valueMB == null)) { - error = true; - // 400 - Bad request - if (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.prepare")+ - " host header missing"); - } - response.setStatus(400); - adapter.log(request, response, 0); - } - - parseHost(valueMB); - - if (!contentDelimitation) { - // If there's no content length - // (broken HTTP/1.0 or HTTP/1.1), assume - // the client is not broken and didn't send a body - inputBuffer.addActiveFilter - (inputFilters[Constants.VOID_FILTER]); - contentDelimitation = true; - } - - // Advertise sendfile support through a request attribute - if (endpoint.getUseSendfile()) { - request.setAttribute("org.apache.tomcat.sendfile.support", - Boolean.TRUE); - } - - // Advertise comet support through a request attribute - if (endpoint.getUseComet()) { - request.setAttribute("org.apache.tomcat.comet.support", - Boolean.TRUE); - } - // Advertise comet timeout support - if (endpoint.getUseCometTimeout()) { - request.setAttribute("org.apache.tomcat.comet.timeout.support", - Boolean.TRUE); - } - } - - @Override protected boolean prepareSendfile(OutputFilter[] outputFilters) { String fileName = (String) request.getAttribute( Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1137451&r1=1137450&r2=1137451&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Sun Jun 19 21:33:55 2011 @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.net.InetAddress; import java.net.Socket; -import java.util.Locale; import org.apache.coyote.ActionCode; import org.apache.coyote.RequestInfo; @@ -30,10 +29,7 @@ import org.apache.coyote.http11.filters. import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; -import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.buf.HexUtils; -import org.apache.tomcat.util.buf.MessageBytes; -import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.JIoEndpoint; import org.apache.tomcat.util.net.SSLSupport; @@ -579,200 +575,9 @@ public class Http11Processor extends Abs } - // ------------------------------------------------------ Connector Methods - - - // ------------------------------------------------------ Protected Methods - /** - * After reading the request headers, we have to setup the request filters. - */ - protected void prepareRequest() { - - http11 = true; - http09 = false; - contentDelimitation = false; - expectation = false; - if (sslSupport != null) { - request.scheme().setString("https"); - } - MessageBytes protocolMB = request.protocol(); - if (protocolMB.equals(Constants.HTTP_11)) { - http11 = true; - protocolMB.setString(Constants.HTTP_11); - } else if (protocolMB.equals(Constants.HTTP_10)) { - http11 = false; - keepAlive = false; - protocolMB.setString(Constants.HTTP_10); - } else if (protocolMB.equals("")) { - // HTTP/0.9 - http09 = true; - http11 = false; - keepAlive = false; - } else { - // Unsupported protocol - http11 = false; - error = true; - // Send 505; Unsupported HTTP version - if (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.prepare")+ - " Unsupported HTTP version \""+protocolMB+"\""); - } - response.setStatus(505); - adapter.log(request, response, 0); - } - - MessageBytes methodMB = request.method(); - if (methodMB.equals(Constants.GET)) { - methodMB.setString(Constants.GET); - } else if (methodMB.equals(Constants.POST)) { - methodMB.setString(Constants.POST); - } - - MimeHeaders headers = request.getMimeHeaders(); - - // Check connection header - MessageBytes connectionValueMB = headers.getValue("connection"); - if (connectionValueMB != null) { - ByteChunk connectionValueBC = connectionValueMB.getByteChunk(); - if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) { - keepAlive = false; - } else if (findBytes(connectionValueBC, - Constants.KEEPALIVE_BYTES) != -1) { - keepAlive = true; - } - } - - MessageBytes expectMB = null; - if (http11) - expectMB = headers.getValue("expect"); - if ((expectMB != null) - && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) { - inputBuffer.setSwallowInput(false); - expectation = true; - } - - // Check user-agent header - if ((restrictedUserAgents != null) && ((http11) || (keepAlive))) { - MessageBytes userAgentValueMB = headers.getValue("user-agent"); - // Check in the restricted list, and adjust the http11 - // and keepAlive flags accordingly - if(userAgentValueMB != null) { - String userAgentValue = userAgentValueMB.toString(); - if (restrictedUserAgents != null && - restrictedUserAgents.matcher(userAgentValue).matches()) { - http11 = false; - keepAlive = false; - } - } - } - - // Check for a full URI (including protocol://host:port/) - ByteChunk uriBC = request.requestURI().getByteChunk(); - if (uriBC.startsWithIgnoreCase("http", 0)) { - - int pos = uriBC.indexOf("://", 0, 3, 4); - int uriBCStart = uriBC.getStart(); - int slashPos = -1; - if (pos != -1) { - byte[] uriB = uriBC.getBytes(); - slashPos = uriBC.indexOf('/', pos + 3); - if (slashPos == -1) { - slashPos = uriBC.getLength(); - // Set URI as "/" - request.requestURI().setBytes - (uriB, uriBCStart + pos + 1, 1); - } else { - request.requestURI().setBytes - (uriB, uriBCStart + slashPos, - uriBC.getLength() - slashPos); - } - MessageBytes hostMB = headers.setValue("host"); - hostMB.setBytes(uriB, uriBCStart + pos + 3, - slashPos - pos - 3); - } - - } - - // Input filter setup - InputFilter[] inputFilters = inputBuffer.getFilters(); - - // Parse transfer-encoding header - MessageBytes transferEncodingValueMB = null; - if (http11) - transferEncodingValueMB = headers.getValue("transfer-encoding"); - if (transferEncodingValueMB != null) { - String transferEncodingValue = transferEncodingValueMB.toString(); - // Parse the comma separated list. "identity" codings are ignored - int startPos = 0; - int commaPos = transferEncodingValue.indexOf(','); - String encodingName = null; - while (commaPos != -1) { - encodingName = transferEncodingValue.substring - (startPos, commaPos).toLowerCase(Locale.ENGLISH).trim(); - if (!addInputFilter(inputFilters, encodingName)) { - // Unsupported transfer encoding - error = true; - // 501 - Unimplemented - response.setStatus(501); - adapter.log(request, response, 0); - } - startPos = commaPos + 1; - commaPos = transferEncodingValue.indexOf(',', startPos); - } - encodingName = transferEncodingValue.substring(startPos) - .toLowerCase(Locale.ENGLISH).trim(); - if (!addInputFilter(inputFilters, encodingName)) { - // Unsupported transfer encoding - error = true; - // 501 - Unimplemented - if (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.prepare")+ - " Unsupported transfer encoding \""+encodingName+"\""); - } - response.setStatus(501); - adapter.log(request, response, 0); - } - } - - // Parse content-length header - long contentLength = request.getContentLengthLong(); - if (contentLength >= 0 && !contentDelimitation) { - inputBuffer.addActiveFilter - (inputFilters[Constants.IDENTITY_FILTER]); - contentDelimitation = true; - } - - MessageBytes valueMB = headers.getValue("host"); - - // Check host header - if (http11 && (valueMB == null)) { - error = true; - // 400 - Bad request - if (log.isDebugEnabled()) { - log.debug(sm.getString("http11processor.request.prepare")+ - " host header missing"); - } - response.setStatus(400); - adapter.log(request, response, 0); - } - - parseHost(valueMB); - - if (!contentDelimitation) { - // If there's no content length - // (broken HTTP/1.0 or HTTP/1.1), assume - // the client is not broken and didn't send a body - inputBuffer.addActiveFilter - (inputFilters[Constants.VOID_FILTER]); - contentDelimitation = true; - } - - } - - @Override protected boolean prepareSendfile(OutputFilter[] outputFilters) { // Should never, ever call this code --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org