If you were going to store a user agent in a database, how large would you accomdate for?
I found this technet article which recommends keeping UA under 200. It doesn't look like this is defined in the HTTP specification at least not that I found. My UA is already 149 characters, and it seems like each version of .NET will be adding to it.
I know I can parse the string out and break it down but I'd rather not.
EDIT
Based on this Blog IE9 will be changing to send the short UA string. This is a good change.
My take on this:
UNIQUE BINARY(32)
(or 64, or 128 depending on your hash length) and hash the UserAgentSome UA strings can get obscenely long. This should spare you the worries. Also enforce a maximum length in your INSERTer to keep UA strings it under 4KB. Unless someone is emailing you in the user-agent, it should not go over that length.
There is no stated limit, only the limit of most HTTP servers. Keeping that in mind however, I would implement a column with a reasonable fixed length (use Google to find a list of known user agents, find the largest and add 50%), and just crop any user agent that is too long - any exceptionally long user agent is probably unique enough even when cropped, or is the result of some kind of bug or "hack" attempt.
Since it's for database purposes and there is no practical limit i'd go for a UserAgents Table with UserAgentId as Int and UserAgentString as NVarChar(MAX) and use a foreign key on the original table.
Assume the user agent string has no limit on its length and prepare to store such a value. As you've seen, length is unpredictable.
In Postgres, there's a text type that accepts strings of unlimited length. Use that.
Most likely though, you'll have to start truncating at some point. Call it good at a reasonably useful increment (200, 1k, 4k) and throw away the rest.
HTTP specification does not limit length of headers at all. However web-servers do limit header size they accept, throwing
413 Entity Too Large
if it exceeds.Depending on web-server and their settings these limits vary from 4KB to 64KB (total for all headers).
Here is one that is 257