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'>{@doc RFC2616} 023 * </ul> 024 */ 025public enum HttpMethod { 026 027 /** {@doc RFC2616.section9#sec9.2 OPTIONS} */ 028 OPTIONS, 029 030 /** {@doc RFC2616.section9#sec9.3 GET} */ 031 GET, 032 033 /** {@doc RFC2616.section9#sec9.4 HEAD} */ 034 HEAD, 035 036 /** {@doc RFC2616.section9#sec9.5 POST} */ 037 POST, 038 039 /** {@doc RFC2616.section9#sec9.6 PUT} */ 040 PUT, 041 042 /** {@doc RFC2616.section9#sec9.7 DELETE} */ 043 DELETE, 044 045 /** {@doc RFC2616.section9#sec9.8 TRACE} */ 046 TRACE, 047 048 /** {@doc RFC2616.section9#sec9.9 CONNECT} */ 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}