You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2008/02/15 12:41:35 UTC
svn commit: r628025 -
/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
Author: rickmcguire
Date: Fri Feb 15 03:41:31 2008
New Revision: 628025
URL: http://svn.apache.org/viewvc?rev=628025&view=rev
Log:
GERONIMO-3857 response header parsing is done incorrectly
Patch provided by Sangjin Lee.
Modified:
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java?rev=628025&r1=628024&r2=628025&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java Fri Feb 15 03:41:31 2008
@@ -80,6 +80,12 @@
/** Line feed character. */
private static final byte LF = 10;
+
+ /** Single space character. */
+ private static final char SP = 32;
+
+ /** Horizontal tab character. */
+ private static final char HT = 9;
/** The decoder. */
@@ -161,9 +167,9 @@
* @throws Exception if any exception occurs
*/
public void decodeHeader(String line, HttpResponseMessage msg) throws Exception {
- int pos = line.indexOf(": ");
+ int pos = line.indexOf(":");
String name = line.substring(0, pos);
- String value = line.substring(pos + 2);
+ String value = trimHeaderValue(line.substring(pos + 1));
NameValuePair nvp = new NameValuePair(name, value);
msg.addHeader(nvp);
@@ -198,6 +204,31 @@
msg.addChallenge(nvp);
}
+ }
+
+ private String trimHeaderValue(String original) {
+ int start = 0;
+ int end = original.length();
+
+ // remove any preceding LWSP chars from the string
+ while (start < end && isLWSPChar(original.charAt(start))) {
+ start++;
+ }
+
+ // remove any trailing LWSP chars from the string
+ while (start < end && isLWSPChar(original.charAt(end - 1))) {
+ end--;
+ }
+
+ return original.substring(start, end);
+ }
+
+ /**
+ * Returns whether the character is a LWSP character (SPACE | HTAB) as
+ * specified by RFC 822.
+ */
+ boolean isLWSPChar(char ch) {
+ return ch == SP || ch == HT;
}
/**