From d64edda9e5205c15ddd485a5b3399b0ddef5dfce Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Fri, 13 Apr 2007 14:01:26 +0000 Subject: [PATCH] Added method to extract a set of allowed methods from the OPTIONS response git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@528488 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/client/methods/HttpOptions.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/java/org/apache/http/client/methods/HttpOptions.java b/src/java/org/apache/http/client/methods/HttpOptions.java index 46cc3e1ea..ac66da611 100644 --- a/src/java/org/apache/http/client/methods/HttpOptions.java +++ b/src/java/org/apache/http/client/methods/HttpOptions.java @@ -33,6 +33,13 @@ package org.apache.http.client.methods; 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. @@ -75,4 +82,20 @@ public class HttpOptions extends HttpRequestBase { 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; + } + }