You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/09/29 04:13:50 UTC
svn commit: r1177152 - in /tomcat/trunk/java/org/apache/coyote/http11:
InternalAprInputBuffer.java InternalInputBuffer.java
InternalNioInputBuffer.java
Author: kkolinko
Date: Thu Sep 29 02:13:50 2011
New Revision: 1177152
URL: http://svn.apache.org/viewvc?rev=1177152&view=rev
Log:
No functional change.
Simplify code and add comments:
- unwrapped nested if().
- s/while()/if()/ where it has only one iteration.
Modified:
tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java?rev=1177152&r1=1177151&r2=1177152&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java Thu Sep 29 02:13:50 2011
@@ -340,11 +340,11 @@ public class InternalAprInputBuffer exte
chr = buf[pos];
- if ((chr == Constants.CR) || (chr == Constants.LF)) {
- if (chr == Constants.LF) {
- pos++;
- return false;
- }
+ if (chr == Constants.CR) {
+ // Skip
+ } else if (chr == Constants.LF) {
+ pos++;
+ return false;
} else {
break;
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java?rev=1177152&r1=1177151&r2=1177152&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalInputBuffer.java Thu Sep 29 02:13:50 2011
@@ -296,11 +296,11 @@ public class InternalInputBuffer extends
chr = buf[pos];
- if ((chr == Constants.CR) || (chr == Constants.LF)) {
- if (chr == Constants.LF) {
- pos++;
- return false;
- }
+ if (chr == Constants.CR) {
+ // Skip
+ } else if (chr == Constants.LF) {
+ pos++;
+ return false;
} else {
break;
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=1177152&r1=1177151&r2=1177152&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Thu Sep 29 02:13:50 2011
@@ -48,9 +48,42 @@ public class InternalNioInputBuffer exte
// -------------------------------------------------------------- Constants
- enum HeaderParseStatus {DONE, HAVE_MORE_HEADERS, NEED_MORE_DATA}
- enum HeaderParsePosition {HEADER_START, HEADER_NAME, HEADER_VALUE,
- HEADER_MULTI_LINE, HEADER_SKIPLINE}
+ enum HeaderParseStatus {
+ DONE, HAVE_MORE_HEADERS, NEED_MORE_DATA
+ }
+
+ enum HeaderParsePosition {
+ /**
+ * Start of a new header. A CRLF here means that there are no more
+ * headers. Any other character starts a header name.
+ */
+ HEADER_START,
+ /**
+ * Reading a header name. All characters of header are HTTP_TOKEN_CHAR.
+ * Header name is followed by ':'. No whitespace is allowed.<br />
+ * Any non-HTTP_TOKEN_CHAR (this includes any whitespace) encountered
+ * before ':' will result in the whole line being ignored.
+ */
+ HEADER_NAME,
+ /**
+ * Reading the header value. We come into this state by two ways:<br />
+ * a) just after the ':' on the first line of the header, b) on the
+ * start of a new line when it is known that it starts with SP or HT.
+ */
+ HEADER_VALUE,
+ /**
+ * Before reading a new line of a header. Once the next byte is peeked,
+ * the state changes without advancing our position. The state becomes
+ * either HEADER_VALUE (if that first byte is SP or HT), or HEADER_START
+ * (otherwise).
+ */
+ HEADER_MULTI_LINE,
+ /**
+ * Reading all bytes until the next CRLF. The line is being ignored.
+ */
+ HEADER_SKIPLINE
+ }
+
// ----------------------------------------------------------- Constructors
@@ -483,11 +516,11 @@ public class InternalNioInputBuffer exte
chr = buf[pos];
- if ((chr == Constants.CR) || (chr == Constants.LF)) {
- if (chr == Constants.LF) {
- pos++;
- return HeaderParseStatus.DONE;
- }
+ if (chr == Constants.CR) {
+ // Skip
+ } else if (chr == Constants.LF) {
+ pos++;
+ return HeaderParseStatus.DONE;
} else {
break;
}
@@ -500,14 +533,13 @@ public class InternalNioInputBuffer exte
// Mark the current buffer position
headerData.start = pos;
headerParsePos = HeaderParsePosition.HEADER_NAME;
- }
+ }
//
// Reading the header name
// Header name is always US-ASCII
//
-
while (headerParsePos == HeaderParsePosition.HEADER_NAME) {
// Read new bytes if needed
@@ -538,8 +570,8 @@ public class InternalNioInputBuffer exte
}
}
-
- while (headerParsePos == HeaderParsePosition.HEADER_SKIPLINE) {
+ // Skip the line and ignore the header
+ if (headerParsePos == HeaderParsePosition.HEADER_SKIPLINE) {
return skipLine();
}
@@ -681,9 +713,29 @@ public class InternalNioInputBuffer exte
private HeaderParseData headerData = new HeaderParseData();
public static class HeaderParseData {
+ /**
+ * When parsing header name: first character of the header.<br />
+ * When parsing header value: first character after ':'.
+ */
int start = 0;
+ /**
+ * When parsing header name: not used (stays as 0).<br />
+ * When parsing header value: starts as the first character after ':'.
+ * Then is increased as far as more bytes of the header are harvested.
+ * Bytes from buf[pos] are copied to buf[realPos]. Thus the string from
+ * [start] to [realPos-1] is the prepared value of the header, with
+ * whitespaces removed as needed.
+ */
int realPos = 0;
+ /**
+ * When parsing header name: not used (stays as 0).<br />
+ * When parsing header value: position after the last not-LWS character.
+ */
int lastSignificantChar = 0;
+ /**
+ * MB that will store the value of the header. It is null while parsing
+ * header name and is created after the name has been parsed.
+ */
MessageBytes headerValue = null;
public void recycle() {
start = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org