001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.http;
018
019import static org.apache.juneau.commons.utils.CollectionUtils.*;
020import static org.apache.juneau.commons.utils.Utils.*;
021
022import java.util.*;
023
024/**
025 * Represents valid HTTP 1.1 method name static strings per the RFC 2616 spec.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
029 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
030 * </ul>
031 */
032public class HttpMethod {
033
034   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2">OPTIONS</a> */
035   public static final String OPTIONS = "OPTIONS";
036
037   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3">GET</a> */
038   public static final String GET = "GET";
039
040   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4">HEAD</a> */
041   public static final String HEAD = "HEAD";
042
043   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5">POST</a> */
044   public static final String POST = "POST";
045
046   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6">PUT</a> */
047   public static final String PUT = "PUT";
048
049   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7">DELETE</a> */
050   public static final String DELETE = "DELETE";
051
052   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.8">TRACE</a> */
053   public static final String TRACE = "TRACE";
054
055   /** <a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.9">CONNECT</a> */
056   public static final String CONNECT = "CONNECT";
057
058   /** <a class="doclink" href="https://tools.ietf.org/html/rfc5789">PATCH</a> */
059   public static final String PATCH = "PATCH";
060
061   /** Special case for a REST method that implements a REST-RPC interface. */
062   public static final String RRPC = "RRPC";
063
064   /** A non-standard value. */
065   public static final String OTHER = "OTHER";
066
067   /** Represents any HTTP method. */
068   public static final String ANY = "*";
069
070   private static final Set<String> NO_BODY_METHODS = u(set("GET", "HEAD", "DELETE", "CONNECT", "OPTIONS", "TRACE"));
071
072   /**
073    * Returns <jk>true</jk> if specified http method has content.
074    * <p>
075    * By default, anything not in this list can have content:  <c>GET, HEAD, DELETE, CONNECT, OPTIONS, TRACE</c>.
076    *
077    * @param name The HTTP method.
078    * @return <jk>true</jk> if specified http method has content.
079    */
080   public static boolean hasContent(String name) {
081      return ! NO_BODY_METHODS.contains(emptyIfNull(name).toUpperCase());
082   }
083}