Author: timw Date: Thu Sep 23 10:38:56 2010 New Revision: 1000400 URL: http://svn.apache.org/viewvc?rev=1000400&view=rev Log: https://issues.apache.org/bugzilla/show_bug.cgi?id=49102
Protecting AJP code -> header/method lookup arrays with getters. No measurable slowdown (especially after a profiling JIT gets done with it). Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java tomcat/trunk/java/org/apache/coyote/ajp/Constants.java Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?rev=1000400&r1=1000399&r2=1000400&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Thu Sep 23 10:38:56 2010 @@ -713,7 +713,7 @@ public class AjpAprProcessor implements // Translate the HTTP method code to a String. byte methodCode = requestHeaderMessage.getByte(); if (methodCode != Constants.SC_M_JK_STORED) { - String methodName = Constants.methodTransArray[methodCode - 1]; + String methodName = Constants.getMethodForCode(methodCode - 1); request.method().setString(methodName); } @@ -747,7 +747,7 @@ public class AjpAprProcessor implements isc &= 0xFF00; if(0xA000 == isc) { requestHeaderMessage.getInt(); // To advance the read position - hName = Constants.headerTransArray[hId - 1]; + hName = Constants.getHeaderForCode(hId - 1); vMB = headers.addValue(hName); } else { // reset hId -- if the header currently being read Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?rev=1000400&r1=1000399&r2=1000400&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Thu Sep 23 10:38:56 2010 @@ -719,7 +719,7 @@ public class AjpProcessor implements Act // Translate the HTTP method code to a String. byte methodCode = requestHeaderMessage.getByte(); if (methodCode != Constants.SC_M_JK_STORED) { - String methodName = Constants.methodTransArray[methodCode - 1]; + String methodName = Constants.getMethodForCode(methodCode - 1); request.method().setString(methodName); } @@ -753,7 +753,7 @@ public class AjpProcessor implements Act isc &= 0xFF00; if(0xA000 == isc) { requestHeaderMessage.getInt(); // To advance the read position - hName = Constants.headerTransArray[hId - 1]; + hName = Constants.getHeaderForCode(hId - 1); vMB = headers.addValue(hName); } else { // reset hId -- if the header currently being read Modified: tomcat/trunk/java/org/apache/coyote/ajp/Constants.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/Constants.java?rev=1000400&r1=1000399&r2=1000400&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/ajp/Constants.java (original) +++ tomcat/trunk/java/org/apache/coyote/ajp/Constants.java Thu Sep 23 10:38:56 2010 @@ -120,7 +120,7 @@ public final class Constants { public static final int MAX_SEND_SIZE = MAX_PACKET_SIZE - SEND_HEAD_LEN; // Translates integer codes to names of HTTP methods - public static final String []methodTransArray = { + private static final String [] methodTransArray = { "OPTIONS", "GET", "HEAD", @@ -149,6 +149,16 @@ public final class Constants { "BASELINE-CONTROL", "MKACTIVITY" }; + + /** + * Converts an AJP coded HTTP method to the method name. + * @param code the coded value + * @return the string value of the method + */ + public static final String getMethodForCode(final int code) { + return methodTransArray[code]; + } + public static final int SC_M_JK_STORED = (byte) 0xFF; // id's for common request headers @@ -170,7 +180,7 @@ public final class Constants { public static final byte SC_A_SSL_KEY_SIZE = 11; // XXX ??? // Translates integer codes to request header names - public static final String []headerTransArray = { + private static final String [] headerTransArray = { "accept", "accept-charset", "accept-encoding", @@ -187,8 +197,17 @@ public final class Constants { "user-agent" }; + /** + * Converts an AJP coded HTTP request header to the header name. + * @param code the coded value + * @return the string value of the header name + */ + public static final String getHeaderForCode(final int code) { + return headerTransArray[code]; + } + // Translates integer codes to response header names - public static final String []responseTransArray = { + private static final String [] responseTransArray = { "Content-Type", "Content-Language", "Content-Length", @@ -201,6 +220,15 @@ public final class Constants { "Status", "WWW-Authenticate" }; + + /** + * Converts an AJP coded response header name to the HTTP response header name. + * @param code the coded value + * @return the string value of the header + */ + public static final String getResponseHeaderForCode(final int code) { + return responseTransArray[code]; + } private static final Hashtable<String,Integer> responseTransHash = new Hashtable<String,Integer>(20); @@ -209,7 +237,7 @@ public final class Constants { try { int i; for (i = 0; i < SC_RESP_AJP13_MAX; i++) { - responseTransHash.put(responseTransArray[i], + responseTransHash.put(getResponseHeaderForCode(i), new Integer(0xA001 + i)); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org