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 w800'> 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 w800'> 037 * From = "From" ":" mailbox 038 * </p> 039 * 040 * <p> 041 * An example is: 042 * <p class='bcode w800'> 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 * <ul class='seealso'> 066 * <li class='extlink'>{@doc ExtRFC2616} 067 * </ul> 068 */ 069@Header("From") 070public class From extends BasicStringHeader { 071 072 private static final long serialVersionUID = 1L; 073 074 /** 075 * Convenience creator. 076 * 077 * @param value 078 * The header value. 079 * <br>Can be any of the following: 080 * <ul> 081 * <li>{@link String} 082 * <li>Anything else - Converted to <c>String</c> then parsed. 083 * </ul> 084 * @return A new {@link From} object. 085 */ 086 public static From of(Object value) { 087 if (value == null) 088 return null; 089 return new From(value); 090 } 091 092 /** 093 * Convenience creator using supplier. 094 * 095 * <p> 096 * Header value is re-evaluated on each call to {@link #getValue()}. 097 * 098 * @param value 099 * The header value supplier. 100 * <br>Can be any of the following: 101 * <ul> 102 * <li>{@link String} 103 * <li>Anything else - Converted to <c>String</c> then parsed. 104 * </ul> 105 * @return A new {@link From} object. 106 */ 107 public static From of(Supplier<?> value) { 108 if (value == null) 109 return null; 110 return new From(value); 111 } 112 113 /** 114 * Constructor. 115 * 116 * @param value 117 * The header value. 118 * <br>Can be any of the following: 119 * <ul> 120 * <li>{@link String} 121 * <li>Anything else - Converted to <c>String</c> then parsed. 122 * <li>A {@link Supplier} of anything on this list. 123 * </ul> 124 */ 125 public From(Object value) { 126 super("From", value); 127 } 128 129 /** 130 * Constructor 131 * 132 * @param value 133 * The header value. 134 */ 135 public From(String value) { 136 this((Object)value); 137 } 138}