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 static org.apache.juneau.common.internal.StringUtils.*;
016import static org.apache.juneau.internal.CollectionUtils.*;
017
018import java.util.*;
019
020/**
021 * Represents valid HTTP 1.1 method name static strings per the RFC 2616 spec.
022 *
023 * <h5 class='section'>See Also:</h5><ul>
024 *    <li class='link'><a class="doclink" href="../../../../index.html#juneau-rest-common">juneau-rest-common</a>
025 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
026 * </ul>
027 */
028public class HttpMethod {
029
030   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2">OPTIONS</a> */
031   public static final String OPTIONS = "OPTIONS";
032
033   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3">GET</a> */
034   public static final String GET = "GET";
035
036   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4">HEAD</a> */
037   public static final String HEAD = "HEAD";
038
039   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5">POST</a> */
040   public static final String POST = "POST";
041
042   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6">PUT</a> */
043   public static final String PUT = "PUT";
044
045   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7">DELETE</a> */
046   public static final String DELETE = "DELETE";
047
048   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.8">TRACE</a> */
049   public static final String TRACE = "TRACE";
050
051   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.9">CONNECT</a> */
052   public static final String CONNECT = "CONNECT";
053
054   /** <a class="doclink" href="https://tools.ietf.org/html/rfc5789">PATCH</a> */
055   public static final String PATCH = "PATCH";
056
057   /** Special case for a REST method that implements a REST-RPC interface. */
058   public static final String RRPC = "RRPC";
059
060   /** A non-standard value. */
061   public static final String OTHER = "OTHER";
062
063   /** Represents any HTTP method. */
064   public static final String ANY = "*";
065
066   private static final Set<String> NO_BODY_METHODS = unmodifiable(set("GET","HEAD","DELETE","CONNECT","OPTIONS","TRACE"));
067
068   /**
069    * Returns <jk>true</jk> if specified http method has content.
070    * <p>
071    * By default, anything not in this list can have content:  <c>GET, HEAD, DELETE, CONNECT, OPTIONS, TRACE</c>.
072    *
073    * @param name The HTTP method.
074    * @return <jk>true</jk> if specified http method has content.
075    */
076   public static boolean hasContent(String name) {
077      return ! NO_BODY_METHODS.contains(emptyIfNull(name).toUpperCase());
078   }
079}