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 w800'>
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 w800'>
041 *    User-Agent     = "User-Agent" ":" 1*( product | comment )
042 * </p>
043 *
044 * <p>
045 * Example:
046 * <p class='bcode w800'>
047 *    User-Agent: CERN-LineMode/2.15 libwww/2.17b3
048 * </p>
049 *
050 * <ul class='seealso'>
051 *    <li class='extlink'>{@doc ExtRFC2616}
052 * </ul>
053 */
054@Header("User-Agent")
055public class UserAgent extends BasicStringHeader {
056
057   private static final long serialVersionUID = 1L;
058
059   /**
060    * Convenience creator.
061    *
062    * @param value
063    *    The header value.
064    *    <br>Can be any of the following:
065    *    <ul>
066    *       <li>{@link String}
067    *       <li>Anything else - Converted to <c>String</c> then parsed.
068    *    </ul>
069    * @return A new {@link UserAgent} object.
070    */
071   public static UserAgent of(Object value) {
072      if (value == null)
073         return null;
074      return new UserAgent(value);
075   }
076
077   /**
078    * Convenience creator using supplier.
079    *
080    * <p>
081    * Header value is re-evaluated on each call to {@link #getValue()}.
082    *
083    * @param value
084    *    The header value supplier.
085    *    <br>Can be any of the following:
086    *    <ul>
087    *       <li>{@link String}
088    *       <li>Anything else - Converted to <c>String</c> then parsed.
089    *    </ul>
090    * @return A new {@link UserAgent} object.
091    */
092   public static UserAgent of(Supplier<?> value) {
093      if (value == null)
094         return null;
095      return new UserAgent(value);
096   }
097
098   /**
099    * Constructor.
100    *
101    * @param value
102    *    The header value.
103    *    <br>Can be any of the following:
104    *    <ul>
105    *       <li>{@link String}
106    *       <li>Anything else - Converted to <c>String</c> then parsed.
107    *       <li>A {@link Supplier} of anything on this list.
108    *    </ul>
109    */
110   public UserAgent(Object value) {
111      super("User-Agent", value);
112   }
113
114   /**
115    * Constructor
116    *
117    * @param value
118    *    The header value.
119    */
120   public UserAgent(String value) {
121      this((Object)value);
122   }
123}