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.header;
018
019import java.util.function.*;
020
021import org.apache.juneau.http.annotation.*;
022
023/**
024 * Represents a parsed <l>Expect</l> HTTP request header.
025 *
026 * <p>
027 * Indicates that particular server behaviors are required by the client.
028 *
029 * <h5 class='figure'>Example</h5>
030 * <p class='bcode'>
031 *    Expect: 100-continue
032 * </p>
033 *
034 * <h5 class='topic'>RFC2616 Specification</h5>
035 *
036 * The Expect request-header field is used to indicate that particular server behaviors are required by the client.
037 * <p class='bcode'>
038 *    Expect       =  "Expect" ":" 1#expectation
039 *    expectation  =  "100-continue" | expectation-extension
040 *    expectation-extension =  token [ "=" ( token | quoted-string )
041 *                             *expect-params ]
042 *    expect-params =  ";" token [ "=" ( token | quoted-string ) ]
043 * </p>
044 *
045 * <p>
046 * A server that does not understand or is unable to comply with any of the expectation values in the Expect field of a
047 * request MUST respond with appropriate error status.
048 * The server MUST respond with a 417 (Expectation Failed) status if any of the expectations cannot be met or, if there
049 * are other problems with the request, some other 4xx status.
050 *
051 * <p>
052 * This header field is defined with extensible syntax to allow for future extensions.
053 * If a server receives a request containing an Expect field that includes an expectation-extension that it does not
054 * support, it MUST respond with a 417 (Expectation Failed) status.
055 *
056 * <p>
057 * Comparison of expectation values is case-insensitive for unquoted tokens (including the 100-continue token), and is
058 * case-sensitive for quoted-string expectation-extensions.
059 *
060 * <p>
061 * The Expect mechanism is hop-by-hop: that is, an HTTP/1.1 proxy MUST return a 417 (Expectation Failed) status if it
062 * receives a request with an expectation that it cannot meet.
063 * However, the Expect request-header itself is end-to-end; it MUST be forwarded if the request is forwarded.
064 *
065 * <p>
066 * Many older HTTP/1.0 and HTTP/1.1 applications do not understand the Expect header.
067 *
068 * <p>
069 * See section 8.2.3 for the use of the 100 (continue) status.
070 *
071 * <h5 class='section'>See Also:</h5><ul>
072 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a>
073 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
074 * </ul>
075 *
076 * @serial exclude
077 */
078@Header("Expect")
079public class Expect extends BasicStringHeader {
080   private static final long serialVersionUID = 1L;
081   private static final String NAME = "Expect";
082
083   /**
084    * Static creator.
085    *
086    * @param value
087    *    The header value.
088    *    <br>Can be <jk>null</jk>.
089    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
090    */
091   public static Expect of(String value) {
092      return value == null ? null : new Expect(value);
093   }
094
095   /**
096    * Static creator with delayed value.
097    *
098    * <p>
099    * Header value is re-evaluated on each call to {@link #getValue()}.
100    *
101    * @param value
102    *    The supplier of the header value.
103    *    <br>Can be <jk>null</jk>.
104    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
105    */
106   public static Expect of(Supplier<String> value) {
107      return value == null ? null : new Expect(value);
108   }
109
110   /**
111    * Constructor.
112    *
113    * @param value
114    *    The header value.
115    *    <br>Can be <jk>null</jk>.
116    */
117   public Expect(String value) {
118      super(NAME, value);
119   }
120
121   /**
122    * Constructor with delayed value.
123    *
124    * <p>
125    * Header value is re-evaluated on each call to {@link #getValue()}.
126    *
127    * @param value
128    *    The supplier of the header value.
129    *    <br>Can be <jk>null</jk>.
130    */
131   public Expect(Supplier<String> value) {
132      super(NAME, value);
133   }
134}