How big can a user agent string get?

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.



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).


My take on this:

  • Use a dedicated table to store only UserAgents (normalize it)
  • In your related tables, store an Foreign Key value to point back to the UserAgent auto-increment primary key field
  • Store the actual UserAgent string in a TEXT field and care not about the length
  • Have another UNIQUE BINARY(32) (or 64, or 128 depending on your hash length) and hash the UserAgent
  • Some 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.


    由于它是为了数据库的目的,并没有实际的限制,我会去用UserAgentId作为Int和UserAgentString作为NVarChar(MAX)UserAgentId并在原始表上使用外键。

    链接地址: http://www.djcxy.com/p/71436.html

    上一篇: 什么是网络浏览器的cookie的最大大小?

    下一篇: 用户代理字符串可以有多大?