001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http.header;
014
015import java.util.function.*;
016
017import org.apache.juneau.http.annotation.*;
018
019/**
020 * Represents a parsed <l>From</l> HTTP request header.
021 *
022 * <p>
023 * The email address of the user making the request.
024 *
025 * <h5 class='figure'>Example</h5>
026 * <p class='bcode'>
027 *    From: user@example.com
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The From request-header field, if given, SHOULD contain an Internet e-mail address for the human user who controls
033 * the requesting user agent.
034 * The address SHOULD be machine-usable, as defined by "mailbox" in RFC 822 [9] as updated by RFC 1123 [8]:
035 *
036 * <p class='bcode'>
037 *    From   = "From" ":" mailbox
038 * </p>
039 *
040 * <p>
041 * An example is:
042 * <p class='bcode'>
043 *    From: webmaster@w3.org
044 * </p>
045 *
046 * <p>
047 * This header field MAY be used for logging purposes and as a means for identifying the source of invalid or unwanted
048 * requests.
049 * It SHOULD NOT be used as an insecure form of access protection.
050 * The interpretation of this field is that the request is being performed on behalf of the person given, who accepts
051 * responsibility for the method performed.
052 * In particular, robot agents SHOULD include this header so that the person responsible for running the robot can be
053 * contacted if problems occur on the receiving end.
054 *
055 * <p>
056 * The Internet e-mail address in this field MAY be separate from the Internet host which issued the request.
057 * For example, when a request is passed through a proxy the original issuer's address SHOULD be used.
058 *
059 * <p>
060 * The client SHOULD NOT send the From header field without the user's approval, as it might conflict with the user's
061 * privacy interests or their site's security policy.
062 * It is strongly recommended that the user be able to disable, enable, and modify the value of this field at any time
063 * prior to a request.
064 *
065 * <h5 class='section'>See Also:</h5><ul>
066 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
067 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
068 * </ul>
069 *
070 * @serial exclude
071 */
072@Header("From")
073public class From extends BasicStringHeader {
074
075   //-----------------------------------------------------------------------------------------------------------------
076   // Static
077   //-----------------------------------------------------------------------------------------------------------------
078
079   private static final long serialVersionUID = 1L;
080   private static final String NAME = "From";
081
082   /**
083    * Static creator.
084    *
085    * @param value
086    *    The header value.
087    *    <br>Can be <jk>null</jk>.
088    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
089    */
090   public static From of(String value) {
091      return value == null ? null : new From(value);
092   }
093
094   /**
095    * Static creator with delayed value.
096    *
097    * <p>
098    * Header value is re-evaluated on each call to {@link #getValue()}.
099    *
100    * @param value
101    *    The supplier of the header value.
102    *    <br>Can be <jk>null</jk>.
103    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
104    */
105   public static From of(Supplier<String> value) {
106      return value == null ? null : new From(value);
107   }
108
109   //-----------------------------------------------------------------------------------------------------------------
110   // Instance
111   //-----------------------------------------------------------------------------------------------------------------
112
113   /**
114    * Constructor.
115    *
116    * @param value
117    *    The header value.
118    *    <br>Can be <jk>null</jk>.
119    */
120   public From(String value) {
121      super(NAME, value);
122   }
123
124   /**
125    * Constructor with delayed value.
126    *
127    * <p>
128    * Header value is re-evaluated on each call to {@link #getValue()}.
129    *
130    * @param value
131    *    The supplier of the header value.
132    *    <br>Can be <jk>null</jk>.
133    */
134   public From(Supplier<String> value) {
135      super(NAME, value);
136   }
137}