hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r595948 - in /jakarta/httpcomponents/httpclient/trunk/module-client: ./ src/main/java/org/apache/http/impl/auth/ src/main/java/org/apache/http/impl/conn/ src/main/java/org/apache/http/impl/cookie/ src/test/java/org/apache/http/impl/cookie/
Date Sat, 17 Nov 2007 13:39:47 GMT
Author: olegk
Date: Sat Nov 17 05:39:46 2007
New Revision: 595948

URL: http://svn.apache.org/viewvc?rev=595948&view=rev
Log:
Re-synched HttpClient trunk with HttpCore trunk  

Added:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
  (with props)
Modified:
    jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAllCookieImpl.java

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml?rev=595948&r1=595947&r2=595948&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml Sat Nov 17 05:39:46 2007
@@ -63,7 +63,7 @@
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpcore</artifactId>
-      <version>4.0-alpha6</version>
+      <version>4.0-alpha7-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>commons-logging</groupId>

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java?rev=595948&r1=595947&r2=595948&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
Sat Nov 17 05:39:46 2007
@@ -40,6 +40,8 @@
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.message.BasicHeaderValueParser;
+import org.apache.http.message.HeaderValueParser;
+import org.apache.http.message.ParserCursor;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.CharArrayBuffer;
 
@@ -120,7 +122,9 @@
         if (!s.equalsIgnoreCase(getSchemeName())) {
             throw new MalformedChallengeException("Invalid scheme identifier: " + s);
         }
-        HeaderElement[] elements = BasicHeaderValueParser.DEFAULT.parseElements(buffer, pos,
buffer.length());
+        HeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
+        ParserCursor cursor = new ParserCursor(pos, buffer.length()); 
+        HeaderElement[] elements = parser.parseElements(buffer, cursor);
         if (elements.length == 0) {
             throw new MalformedChallengeException("Authentication challenge is empty");
         }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java?rev=595948&r1=595947&r2=595948&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java
Sat Nov 17 05:39:46 2007
@@ -43,6 +43,7 @@
 import org.apache.http.impl.io.AbstractMessageParser;
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.message.LineParser;
+import org.apache.http.message.ParserCursor;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.CharArrayBuffer;
 
@@ -75,13 +76,15 @@
         this.lineBuf.clear();
         //read out the HTTP status string
         int count = 0;
+        ParserCursor cursor = null;
         do {
             int i = sessionBuffer.readLine(this.lineBuf);
             if (i == -1 && count == 0) {
                 // The server just dropped connection on us
                 throw new NoHttpResponseException("The target server failed to respond");
             }
-            if (lineParser.hasProtocolVersion(this.lineBuf, 0)) {
+            cursor = new ParserCursor(0, this.lineBuf.length());
+            if (lineParser.hasProtocolVersion(this.lineBuf, cursor)) {
                 // Got one
                 break;
             } else if (i == -1 || count >= this.maxGarbageLines) {
@@ -92,7 +95,7 @@
             count++;
         } while(true);
         //create the status line from the status string
-        StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, 0, this.lineBuf.length());
+        StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
         return this.responseFactory.newHttpResponse(statusline, null);
     }
 

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java?rev=595948&r1=595947&r2=595948&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
Sat Nov 17 05:39:46 2007
@@ -31,6 +31,7 @@
 
 package org.apache.http.impl.cookie;
 
+import org.apache.http.FormattedHeader;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
 import org.apache.http.cookie.ClientCookie;
@@ -38,8 +39,8 @@
 import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.MalformedCookieException;
 import org.apache.http.cookie.SM;
-import org.apache.http.message.BasicHeaderValueParser;
 import org.apache.http.message.BufferedHeader;
+import org.apache.http.message.ParserCursor;
 import org.apache.http.util.CharArrayBuffer;
 
 /**
@@ -121,7 +122,24 @@
         }
         HeaderElement[] elems = null;
         if (isNetscapeCookie) {
-            elems = new HeaderElement[] { BasicHeaderValueParser.parseHeaderElement(headervalue,
null) };
+            NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
+            CharArrayBuffer buffer;
+            ParserCursor cursor;
+            if (header instanceof FormattedHeader) {
+                buffer = ((FormattedHeader) header).getBuffer();
+                cursor = new ParserCursor(
+                        ((FormattedHeader) header).getValuePos(), 
+                        buffer.length());
+            } else {
+                String s = header.getValue();
+                if (s == null) {
+                    throw new MalformedCookieException("Header value is null");
+                }
+                buffer = new CharArrayBuffer(s.length());
+                buffer.append(s);
+                cursor = new ParserCursor(0, buffer.length());
+            }
+            elems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
         } else {
             elems = header.getElements();
         }

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java?rev=595948&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
Sat Nov 17 05:39:46 2007
@@ -0,0 +1,78 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.cookie;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.HeaderElement;
+import org.apache.http.NameValuePair;
+import org.apache.http.ParseException;
+import org.apache.http.message.BasicHeaderElement;
+import org.apache.http.message.BasicHeaderValueParser;
+import org.apache.http.message.ParserCursor;
+import org.apache.http.util.CharArrayBuffer;
+
+public class NetscapeDraftHeaderParser {
+
+    public final static NetscapeDraftHeaderParser DEFAULT = new NetscapeDraftHeaderParser();
+    
+    private final static char[] DELIMITERS = new char[] { ';' };
+    
+    private final BasicHeaderValueParser nvpParser;
+    
+    public NetscapeDraftHeaderParser() {
+        super();
+        this.nvpParser = BasicHeaderValueParser.DEFAULT;
+    }
+    
+    public HeaderElement parseHeader(
+            final CharArrayBuffer buffer,
+            final ParserCursor cursor) throws ParseException {
+        if (buffer == null) {
+            throw new IllegalArgumentException("Char array buffer may not be null");
+        }
+        if (cursor == null) {
+            throw new IllegalArgumentException("Parser cursor may not be null");
+        }
+        NameValuePair nvp = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
+        List params = new ArrayList(); 
+        while (!cursor.atEnd()) {
+            NameValuePair param = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
+            params.add(param);
+        }
+        return new BasicHeaderElement(
+                nvp.getName(), 
+                nvp.getValue(), (NameValuePair[]) params.toArray(new NameValuePair[params.size()]));
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java?rev=595948&r1=595947&r2=595948&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
Sat Nov 17 05:39:46 2007
@@ -31,6 +31,7 @@
 
 package org.apache.http.impl.cookie;
 
+import org.apache.http.FormattedHeader;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
 import org.apache.http.cookie.ClientCookie;
@@ -38,8 +39,8 @@
 import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.MalformedCookieException;
 import org.apache.http.cookie.SM;
-import org.apache.http.message.BasicHeaderValueParser;
 import org.apache.http.message.BufferedHeader;
+import org.apache.http.message.ParserCursor;
 import org.apache.http.util.CharArrayBuffer;
 
 /**
@@ -105,8 +106,24 @@
         if (origin == null) {
             throw new IllegalArgumentException("Cookie origin may not be null");
         }
-        String headervalue = header.getValue();
-        return parse(new HeaderElement[] { BasicHeaderValueParser.parseHeaderElement(headervalue,
null) }, origin);
+        NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
+        CharArrayBuffer buffer;
+        ParserCursor cursor;
+        if (header instanceof FormattedHeader) {
+            buffer = ((FormattedHeader) header).getBuffer();
+            cursor = new ParserCursor(
+                    ((FormattedHeader) header).getValuePos(), 
+                    buffer.length());
+        } else {
+            String s = header.getValue();
+            if (s == null) {
+                throw new MalformedCookieException("Header value is null");
+            }
+            buffer = new CharArrayBuffer(s.length());
+            buffer.append(s);
+            cursor = new ParserCursor(0, buffer.length());
+        }
+        return parse(new HeaderElement[] { parser.parseHeader(buffer, cursor) }, origin);
     }
 
     public Header[] formatCookies(final Cookie[] cookies) {

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAllCookieImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAllCookieImpl.java?rev=595948&r1=595947&r2=595948&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAllCookieImpl.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAllCookieImpl.java
Sat Nov 17 05:39:46 2007
@@ -47,6 +47,7 @@
         suite.addTest(TestBasicCookieAttribHandlers.suite());
         suite.addTest(TestNetscapeCookieAttribHandlers.suite());
         suite.addTest(TestRFC2109CookieAttribHandlers.suite());
+        suite.addTest(TestNetscapeDraftHeaderParser.suite());
         suite.addTest(TestBrowserCompatSpec.suite());
         suite.addTest(TestCookieNetscapeDraft.suite());
         suite.addTest(TestCookieRFC2109Spec.suite());

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java?rev=595948&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
Sat Nov 17 05:39:46 2007
@@ -0,0 +1,96 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * 
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.cookie;
+
+import org.apache.http.HeaderElement;
+import org.apache.http.NameValuePair;
+import org.apache.http.message.ParserCursor;
+import org.apache.http.util.CharArrayBuffer;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link NetscapeDraftHeaderParser}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestNetscapeDraftHeaderParser extends TestCase {
+
+    public TestNetscapeDraftHeaderParser(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestNetscapeDraftHeaderParser.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestNetscapeDraftHeaderParser.class);
+    }
+
+    public void testNetscapeCookieParsing() throws Exception {
+        NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
+        
+        String s = 
+            "name  = value; test; test1 =  stuff,with,commas   ; test2 =  \"stuff; stuff\";
test3=\"stuff";
+        CharArrayBuffer buffer = new CharArrayBuffer(16);
+        buffer.append(s);
+        ParserCursor cursor = new ParserCursor(0, s.length());
+        
+        HeaderElement he = parser.parseHeader(buffer, cursor);
+        assertEquals("name", he.getName());
+        assertEquals("value", he.getValue());
+        NameValuePair[] params = he.getParameters();
+        assertEquals("test", params[0].getName());
+        assertEquals(null, params[0].getValue());
+        assertEquals("test1", params[1].getName());
+        assertEquals("stuff,with,commas", params[1].getValue());
+        assertEquals("test2", params[2].getName());
+        assertEquals("stuff; stuff", params[2].getValue());
+        assertEquals("test3", params[3].getName());
+        assertEquals("\"stuff", params[3].getValue());
+        assertEquals(s.length(), cursor.getPos());
+        assertTrue(cursor.atEnd());
+
+        s = "  ";
+        buffer = new CharArrayBuffer(16);
+        buffer.append(s);
+        cursor = new ParserCursor(0, s.length());
+        he = parser.parseHeader(buffer, cursor);
+        assertEquals("", he.getName());
+        assertEquals(null, he.getValue());
+    }
+
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message