001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http;
014
015import java.util.*;
016
017/**
018 * Represents valid HTTP 1.1 method names per the RFC 2616 spec.
019 * 
020 * <h5 class='section'>See Also:</h5>
021 * <ul class='doctree'>
022 *    <li class='extlink'><a class='doclink' href='https://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a>
023 * </ul>
024 */
025public enum HttpMethod {
026
027   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2" class="doclink">OPTIONS</a> */
028   OPTIONS,
029
030   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3" class="doclink">GET</a> */
031   GET,
032
033   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4" class="doclink">HEAD</a> */
034   HEAD,
035
036   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5" class="doclink">POST</a> */
037   POST,
038
039   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6" class="doclink">PUT</a> */
040   PUT,
041
042   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7" class="doclink">DELETE</a> */
043   DELETE,
044
045   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.8" class="doclink">TRACE</a> */
046   TRACE,
047
048   /** <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.9" class="doclink">CONNECT</a> */
049   CONNECT,
050
051   /** A non-standard value. */
052   OTHER;
053
054   private static final Map<String,HttpMethod> cache = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
055   static {
056      cache.put("OPTIONS", OPTIONS);
057      cache.put("GET", GET);
058      cache.put("HEAD", HEAD);
059      cache.put("POST", POST);
060      cache.put("PUT", PUT);
061      cache.put("DELETE", DELETE);
062      cache.put("TRACE", TRACE);
063      cache.put("CONNECT", CONNECT);
064   }
065
066   /**
067    * Returns the enum for the specified key.
068    * 
069    * <p>
070    * Case is ignored.
071    * 
072    * @param key The HTTP method name.
073    * @return The HttpMethod enum, or {@link #OTHER} if it's not a standard method name.
074    */
075   public static HttpMethod forString(String key) {
076      HttpMethod m = cache.get(key);
077      return m == null ? OTHER : m;
078   }
079}