Author: sjlee
Date: Tue Sep 1 03:10:00 2009
New Revision: 809808
URL: http://svn.apache.org/viewvc?rev=809808&view=rev
Log:
ASYNCWEB-36
Fixed logic of decoding lines in the HTTP response. Parsing an empty CRLF in
HttpDecoder.decodeLine() and decodeHeaderLine() should return a non-null empty
string, as returning null means it has a partial line. Removed the unnecessary
check for the terminator position. Also added a unit test.
Modified:
mina/asyncweb/branches/1.0-mina1/client/src/main/java/org/apache/asyncweb/client/codec/HttpDecoder.java
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ResponseHeaderParsingTest.java
Modified:
mina/asyncweb/branches/1.0-mina1/client/src/main/java/org/apache/asyncweb/client/codec/HttpDecoder.java
URL:
http://svn.apache.org/viewvc/mina/asyncweb/branches/1.0-mina1/client/src/main/java/org/apache/asyncweb/client/codec/HttpDecoder.java?rev=809808&r1=809807&r2=809808&view=diff
==============================================================================
---
mina/asyncweb/branches/1.0-mina1/client/src/main/java/org/apache/asyncweb/client/codec/HttpDecoder.java
(original)
+++
mina/asyncweb/branches/1.0-mina1/client/src/main/java/org/apache/asyncweb/client/codec/HttpDecoder.java
Tue Sep 1 03:10:00 2009
@@ -108,7 +108,9 @@
*
* @param in ByteBuffer containing data
*
- * @return a <code>String</code> representing the decoded line
+ * @return a <code>String</code> representing the decoded line, an empty
+ * String if we encountered an empty CR/LF, or null if we don't have a full
+ * line to process
*
* @throws Exception for any Exception that is encountered
*/
@@ -136,12 +138,9 @@
return null;
}
- String result = null;
- if (terminatorPos > 1) {
- ByteBuffer line = in.slice();
- line.limit(terminatorPos - beginPos - 1);
- result = line.getString(decoder.get());
- }
+ ByteBuffer line = in.slice();
+ line.limit(terminatorPos - beginPos - 1);
+ String result = line.getString(decoder.get());
in.position(terminatorPos + 1);
@@ -158,7 +157,9 @@
*
* @param in ByteBuffer containing data
*
- * @return a <code>String</code> representing the decoded line
+ * @return a <code>String</code> representing the decoded line, an empty
+ * String if we encountered an empty CR/LF, or null if we don't have a full
+ * line to process
*
* @throws Exception for any Exception that is encountered
*/
@@ -205,12 +206,9 @@
return null;
}
- String result = null;
- if (terminatorPos > 1) {
- ByteBuffer line = in.slice();
- line.limit(terminatorPos - beginPos - 1);
- result = line.getString(decoder.get());
- }
+ ByteBuffer line = in.slice();
+ line.limit(terminatorPos - beginPos - 1);
+ String result = line.getString(decoder.get());
in.position(terminatorPos + 1);
Modified:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ResponseHeaderParsingTest.java
URL:
http://svn.apache.org/viewvc/mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ResponseHeaderParsingTest.java?rev=809808&r1=809807&r2=809808&view=diff
==============================================================================
---
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ResponseHeaderParsingTest.java
(original)
+++
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ResponseHeaderParsingTest.java
Tue Sep 1 03:10:00 2009
@@ -29,6 +29,7 @@
+ "\r\n"
+ "<html></html>";
private static final String EMPTY_VALUE_COOKIE = "token=; path=/;
expires=Thu, 01 Jan 1970 00:00:00 GMT";
+ private static final String CRLF = "\r\n";
public void testParsing() throws Exception {
ByteBuffer buffer = ByteBuffer.allocate(TEST_RESPONSE.length());
@@ -65,4 +66,16 @@
assertEquals("/", c.getPath());
assertEquals(DateUtil.parseDate("Thu, 01 Jan 1970 00:00:00 GMT"),
c.getExpires());
}
+
+ public void testParsingEmptyCRLF() throws Exception {
+ ByteBuffer buffer = ByteBuffer.allocate(CRLF.length());
+ buffer.put(CRLF.getBytes());
+ buffer.flip();
+
+ HttpDecoder decoder = new HttpDecoder();
+ String line = decoder.decodeHeaderLine(buffer);
+ // we should get a non-null empty string
+ assertTrue(line != null);
+ assertEquals("", line);
+ }
}