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