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
This commit is contained in:
parent
58113ab702
commit
d64edda9e5
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue