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