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