mobile/android/thirdparty/ch/boye/httpclientandroidlib/client/methods/HttpOptions.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * ====================================================================
     3  * Licensed to the Apache Software Foundation (ASF) under one
     4  * or more contributor license agreements.  See the NOTICE file
     5  * distributed with this work for additional information
     6  * regarding copyright ownership.  The ASF licenses this file
     7  * to you under the Apache License, Version 2.0 (the
     8  * "License"); you may not use this file except in compliance
     9  * with the License.  You may obtain a copy of the License at
    10  *
    11  *   http://www.apache.org/licenses/LICENSE-2.0
    12  *
    13  * Unless required by applicable law or agreed to in writing,
    14  * software distributed under the License is distributed on an
    15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16  * KIND, either express or implied.  See the License for the
    17  * specific language governing permissions and limitations
    18  * under the License.
    19  * ====================================================================
    20  *
    21  * This software consists of voluntary contributions made by many
    22  * individuals on behalf of the Apache Software Foundation.  For more
    23  * information on the Apache Software Foundation, please see
    24  * <http://www.apache.org/>.
    25  *
    26  */
    28 package ch.boye.httpclientandroidlib.client.methods;
    30 import java.net.URI;
    31 import java.util.HashSet;
    32 import java.util.Set;
    34 import ch.boye.httpclientandroidlib.annotation.NotThreadSafe;
    36 import ch.boye.httpclientandroidlib.Header;
    37 import ch.boye.httpclientandroidlib.HeaderElement;
    38 import ch.boye.httpclientandroidlib.HeaderIterator;
    39 import ch.boye.httpclientandroidlib.HttpResponse;
    41 /**
    42  * HTTP OPTIONS method.
    43  * <p>
    44  * The HTTP OPTIONS method is defined in section 9.2 of
    45  * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
    46  * <blockquote>
    47  *  The OPTIONS method represents a request for information about the
    48  *  communication options available on the request/response chain
    49  *  identified by the Request-URI. This method allows the client to
    50  *  determine the options and/or requirements associated with a resource,
    51  *  or the capabilities of a server, without implying a resource action
    52  *  or initiating a resource retrieval.
    53  * </blockquote>
    54  * </p>
    55  *
    56  * @since 4.0
    57  */
    58 @NotThreadSafe
    59 public class HttpOptions extends HttpRequestBase {
    61     public final static String METHOD_NAME = "OPTIONS";
    63     public HttpOptions() {
    64         super();
    65     }
    67     public HttpOptions(final URI uri) {
    68         super();
    69         setURI(uri);
    70     }
    72     /**
    73      * @throws IllegalArgumentException if the uri is invalid.
    74      */
    75     public HttpOptions(final String uri) {
    76         super();
    77         setURI(URI.create(uri));
    78     }
    80     @Override
    81     public String getMethod() {
    82         return METHOD_NAME;
    83     }
    85     public Set<String> getAllowedMethods(final HttpResponse response) {
    86         if (response == null) {
    87             throw new IllegalArgumentException("HTTP response may not be null");
    88         }
    90         HeaderIterator it = response.headerIterator("Allow");
    91         Set<String> methods = new HashSet<String>();
    92         while (it.hasNext()) {
    93             Header header = it.nextHeader();
    94             HeaderElement[] elements = header.getElements();
    95             for (HeaderElement element : elements) {
    96                 methods.add(element.getName());
    97             }
    98         }
    99         return methods;
   100     }
   102 }

mercurial