Is there an RFC, official standard, or template for creating a User Agent string? The iphone's user-agent string seems strange...
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16
A browser's User-Agent string (UA) helps identify which browser is being used, what version, and on which operating system. When feature detection APIs are not available, use the UA to customize behavior or content to specific browser versions.
Described in the HTTP standard, the User-Agent string contains a number of tokens that refer to various aspects of the request, including the browser's name and version, rendering engine, device's model number, operating system and its version, etc.
The User-Agent (UA) string is contained in the HTTP headers and is intended to identify devices requesting online content. The User-Agent tells the server what the visiting device is (among many other things) and this information can be used to determine what content to return.
Google Chrome Chrome's user agent switcher is part of its Developer Tools. Open them by clicking the menu button and selecting More Tools > Developer Tools. You can also use press Ctrl+Shift+I on your keyboard.
The User-Agent
header is part of the RFC7231
, which is an improved version of the RFC1945
, where it states:
The
User-Agent
request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user agent limitations. User agents SHOULD include this field with requests. The field can contain multipleproduct
tokens (section 3.8) andcomments
identifying the agent and any subproducts which form a significant part of the user agent. By convention, theproduct
tokens are listed in order of their significance for identifying the application.
User-Agent = "User-Agent" ":" 1*( product | comment )
Where product
is defined as:
product = token ["/" product-version] product-version = token token = 1*<any CHAR except CTLs or separators>
And comment
as:
comment = "(" *( ctext | quoted-pair | comment ) ")" ctext = <any TEXT excluding "(" and ")">
And other rules, for reference:
CTL = <control characters, e.g. ASCII 0x00 through 0x0F and 0x7F> separators = "(" | ")" | "<" | ">" | "@" "," | ";" | ":" | "\" | <"> "/" | "[" | "]" | "?" | "=" "{" | "}" | SP | HT SP = <ASCII space 0x20, i.e. " "> HT = <ASCII horizontal tab 0x09, aka '\t'>
Note that this means that product
strings cannot contain spaces, but comment
strings can.
Here are some valid examples of product
strings (with and without product-version
strings):
# Single `product` without product-version: Foobar Foobar-baz # Single `product` with product-version: Foobar/abc Foobar/1.0.0 Foobar/2021.44.30.15-b917dc
Here are some valid examples of comment
strings; note how all strings are enclosed in matched parentheses (
)
:
# This was the default `comment` used by Internet Explorer 11: (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) # You can put almost any text inside a comment: (Why are you looking at HTTP headers? Go outside, find love, do some good in the world) # Note that `comment` strings can also be nested, provided their delimiting parentheses are matched, for example: (Outer comment (Inner comment))
As a User-Agent
header's value is comprised of arbitrary product
and comment
strings, these are all valid User-Agent
headers:
User-Agent: Foobar User-Agent: Foobar/2021.44.30.15-b917dc User-Agent: MyProduct Foobar/2021.44.30.15-b917dc User-Agent: Tsom/OfraHaza (Life is short and love is always over in the morning) AnotherProduct
This is specified in RFC 1945 in the section on Request Headers. It is not a very standardized format, though, and user agents tend to put whatever they want in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With