hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r594946 - in /jakarta/httpcomponents/httpclient/trunk: ./ module-client/ module-client/src/main/java/org/apache/http/client/methods/ module-client/src/test/java/org/apache/http/client/ module-client/src/test/java/org/apache/http/client/meth...
Date Wed, 14 Nov 2007 16:59:17 GMT
Author: olegk
Date: Wed Nov 14 08:59:15 2007
New Revision: 594946

URL: http://svn.apache.org/viewvc?rev=594946&view=rev
Log:
HTTPCLIENT-688: HttpOptions#getAllowedMethods can now handle multiple Allow headers

Contributed by Andrea Selva <selva.andre at gmail.com>
Reviewed by Oleg Kalnichevski

Added:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestAllMethods.java
  (with props)
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestHttpOptions.java
  (with props)
Modified:
    jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    jakarta/httpcomponents/httpclient/trunk/module-client/   (props changed)
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java

Modified: jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=594946&r1=594945&r2=594946&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Wed Nov 14 08:59:15 2007
@@ -1,3 +1,11 @@
+Changes since 4.0 Alpha 2
+-------------------
+
+* [HTTPCLIENT-688] HttpOptions#getAllowedMethods can now handle multiple 
+  Allow headers
+  Contributed by Andrea Selva <selva.andre at gmail.com>
+
+
 Release 4.0 Alpha 2
 -------------------
 

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Nov 14 08:59:15 2007
@@ -2,3 +2,4 @@
 .classpath
 .project
 bin
+lib

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java?rev=594946&r1=594945&r2=594946&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpOptions.java
Wed Nov 14 08:59:15 2007
@@ -33,14 +33,13 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
+import org.apache.http.HeaderIterator;
 import org.apache.http.HttpResponse;
-import org.apache.http.ParseException;
 
 /**
  * HTTP OPTIONS method.
@@ -83,20 +82,19 @@
         return METHOD_NAME;
     }
     
-    public Set getAllowedMethods(final HttpResponse response)
-        throws ParseException {
-
+    public Set getAllowedMethods(final HttpResponse response) {
         if (response == null) {
             throw new IllegalArgumentException("HTTP response may not be null");
         }
-        Header header = response.getFirstHeader("Allow");
-        if (header == null) {
-            return Collections.EMPTY_SET;
-        }
-        HeaderElement[] elements = header.getElements();
-        Set methods = new HashSet(elements.length);
-        for (int i = 0; i < elements.length; i++) {
-            methods.add(elements[i].getName());
+        
+        HeaderIterator it = response.headerIterator("Allow");
+        Set methods = new HashSet();
+        while (it.hasNext()) {
+            Header header = it.nextHeader();
+            HeaderElement[] elements = header.getElements();
+            for (int i = 0; i < elements.length; i++) {
+                methods.add(elements[i].getName());
+            }
         }
         return methods;
     }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java?rev=594946&r1=594945&r2=594946&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/TestAll.java
Wed Nov 14 08:59:15 2007
@@ -34,6 +34,7 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.http.client.methods.TestAllMethods;
 import org.apache.http.client.protocol.TestAllProtocol;
 import org.apache.http.conn.TestAllConn;
 import org.apache.http.cookie.TestAllCookie;
@@ -55,6 +56,7 @@
         suite.addTest(TestAllConn.suite());
         suite.addTest(TestAllConnImpl.suite());
         suite.addTest(TestAllProtocol.suite());        
+        suite.addTest(TestAllMethods.suite());        
         return suite;
     }
 

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestAllMethods.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestAllMethods.java?rev=594946&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestAllMethods.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestAllMethods.java
Wed Nov 14 08:59:15 2007
@@ -0,0 +1,54 @@
+/*
+ * $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.client.methods;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestAllMethods extends TestCase {
+
+    public TestAllMethods(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.addTest(TestHttpOptions.suite());
+        return suite;
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestAllMethods.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+}

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

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

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

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestHttpOptions.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestHttpOptions.java?rev=594946&view=auto
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestHttpOptions.java
(added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/client/methods/TestHttpOptions.java
Wed Nov 14 08:59:15 2007
@@ -0,0 +1,77 @@
+/*
+ * $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.client.methods;
+
+import java.io.IOException;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.ProtocolVersion;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
+
+public class TestHttpOptions extends TestCase {
+
+    // ------------------------------------------------------------ Constructor
+    public TestHttpOptions(final String testName) throws IOException {
+        super(testName);
+    }
+
+    // ------------------------------------------------------------------- Main
+    public static void main(String args[]) {
+        String[] testCaseName = { TestHttpOptions.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        return new TestSuite(TestHttpOptions.class);
+    }
+
+    public void testMultipleAllows() {
+        ProtocolVersion proto = new ProtocolVersion("HTTP", 1, 1);
+        BasicStatusLine line = new BasicStatusLine(proto, 200, "test reason"); 
+        BasicHttpResponse resp = new BasicHttpResponse(line);
+        resp.addHeader("Allow", "POST");
+        resp.addHeader("Allow", "GET");
+
+        HttpOptions opt = new HttpOptions();
+        Set methodsName = opt.getAllowedMethods(resp);
+        
+        assertTrue(methodsName.contains("POST"));
+        assertTrue(methodsName.contains("GET"));
+    }
+    
+}

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

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

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



Mime
View raw message