hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r528488 - /jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpOptions.java
Date Fri, 13 Apr 2007 14:01:27 GMT
Author: olegk
Date: Fri Apr 13 07:01:26 2007
New Revision: 528488

URL: http://svn.apache.org/viewvc?view=rev&rev=528488
Log:
Added method to extract a set of allowed methods from the OPTIONS response

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpOptions.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpOptions.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpOptions.java?view=diff&rev=528488&r1=528487&r2=528488
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpOptions.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpOptions.java
Fri Apr 13 07:01:26 2007
@@ -33,6 +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.HttpResponse;
 
 /**
  * HTTP OPTIONS method.
@@ -73,6 +80,22 @@
 
     public String getMethod() {
         return METHOD_NAME;
+    }
+    
+    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());
+        }
+        return methods;
     }
     
 }



Mime
View raw message