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 081 //----------------------------------------------------------------------------------------------------------------- 082 // Static 083 //----------------------------------------------------------------------------------------------------------------- 084 085 private static final long serialVersionUID = 1L; 086 private static final String NAME = "Expect"; 087 088 /** 089 * Static creator. 090 * 091 * @param value 092 * The header value. 093 * <br>Can be <jk>null</jk>. 094 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 095 */ 096 public static Expect of(String value) { 097 return value == null ? null : new Expect(value); 098 } 099 100 /** 101 * Static creator with delayed value. 102 * 103 * <p> 104 * Header value is re-evaluated on each call to {@link #getValue()}. 105 * 106 * @param value 107 * The supplier of the header value. 108 * <br>Can be <jk>null</jk>. 109 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 110 */ 111 public static Expect of(Supplier<String> value) { 112 return value == null ? null : new Expect(value); 113 } 114 115 //----------------------------------------------------------------------------------------------------------------- 116 // Instance 117 //----------------------------------------------------------------------------------------------------------------- 118 119 /** 120 * Constructor. 121 * 122 * @param value 123 * The header value. 124 * <br>Can be <jk>null</jk>. 125 */ 126 public Expect(String value) { 127 super(NAME, value); 128 } 129 130 /** 131 * Constructor with delayed value. 132 * 133 * <p> 134 * Header value is re-evaluated on each call to {@link #getValue()}. 135 * 136 * @param value 137 * The supplier of the header value. 138 * <br>Can be <jk>null</jk>. 139 */ 140 public Expect(Supplier<String> value) { 141 super(NAME, value); 142 } 143}