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>User-Agent</l> HTTP request header.
021 *
022 * <p>
023 * The user agent string of the user agent.
024 *
025 * <h5 class='figure'>Example</h5>
026 * <p class='bcode'>
027 *    User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/21.0
028 * </p>
029 *
030 * <h5 class='topic'>RFC2616 Specification</h5>
031 *
032 * The User-Agent request-header field contains information about the user agent originating the request.
033 * This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for
034 * the sake of tailoring responses to avoid particular user agent limitations.
035 * User agents SHOULD include this field with requests.
036 * The field can contain multiple product tokens (section 3.8) and comments identifying the agent and any sub-products
037 * which form a significant part of the user agent.
038 * By convention, the product tokens are listed in order of their significance for identifying the application.
039 *
040 * <p class='bcode'>
041 *    User-Agent     = "User-Agent" ":" 1*( product | comment )
042 * </p>
043 *
044 * <p>
045 * Example:
046 * <p class='bcode'>
047 *    User-Agent: CERN-LineMode/2.15 libwww/2.17b3
048 * </p>
049 *
050 * <h5 class='section'>See Also:</h5><ul>
051 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
052 *    <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>
053 * </ul>
054 *
055 * @serial exclude
056 */
057@Header("User-Agent")
058public class UserAgent extends BasicStringHeader {
059
060   //-----------------------------------------------------------------------------------------------------------------
061   // Static
062   //-----------------------------------------------------------------------------------------------------------------
063
064   private static final long serialVersionUID = 1L;
065   private static final String NAME = "User-Agent";
066
067   /**
068    * Static creator.
069    *
070    * @param value
071    *    The header value.
072    *    <br>Can be <jk>null</jk>.
073    * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>.
074    */
075   public static UserAgent of(String value) {
076      return value == null ? null : new UserAgent(value);
077   }
078
079   /**
080    * Static creator with delayed value.
081    *
082    * <p>
083    * Header value is re-evaluated on each call to {@link #getValue()}.
084    *
085    * @param value
086    *    The supplier of 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 UserAgent of(Supplier<String> value) {
091      return value == null ? null : new UserAgent(value);
092   }
093
094   //-----------------------------------------------------------------------------------------------------------------
095   // Instance
096   //-----------------------------------------------------------------------------------------------------------------
097
098   /**
099    * Constructor.
100    *
101    * @param value
102    *    The header value.
103    *    <br>Can be <jk>null</jk>.
104    */
105   public UserAgent(String value) {
106      super(NAME, value);
107   }
108
109   /**
110    * Constructor with delayed value.
111    *
112    * <p>
113    * Header value is re-evaluated on each call to {@link #getValue()}.
114    *
115    * @param value
116    *    The supplier of the header value.
117    *    <br>Can be <jk>null</jk>.
118    */
119   public UserAgent(Supplier<String> value) {
120      super(NAME, value);
121   }
122}