views:

2662

answers:

7

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.


+1  A: 

I'll give you the standard answer:

Take the largest possible value you can possibly imagine it being, double it, and that's your answer.

Ed Marty
heh so how large do you think it will be?
JoshBerke
Twice whatever I think it is, of course. Though 256 seems like a nice round number to double.
Ed Marty
I find it funny whenever we don't know what a good length would be we always end up with 256 or another multiple of 2.
JoshBerke
It compresses well!
Ed Marty
Well 512 sounds good that gives me at least 10 years of .net releases and other junk to accumulate and by then I hope to be retired. Thanks again
JoshBerke
@Josh: "by then I hope to be retired"... where have I heard that before?! ;-)
Cerebrus
+4  A: 

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.

Diadistis
Interesting idea, I never thought of normalizing it...makes sense...
JoshBerke
+10  A: 

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 these limits vary from 4KB to 64KB.

vartec
Apache limits the maximum field length to 8k (http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize).
Gumbo
I'm less concerned with server limits since I am on IIS, I know it won't ever be bigger then their limit which is still preety large if memory serves....
JoshBerke
@Josh -- memory serves you well, on IIS it's 16K by default. ;-)
vartec
Which I better not get a 16k user agent....
JoshBerke
+1  A: 

There is no stated limit, only the limit of most HTTP servers. Keeping that in mind however, I would impliment 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 and 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.

David
+2  A: 

I got this user agent today, overflowing our vendor's storage field:

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; MDDR; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)

Ridiculous! 229 chars?

So take that size, double it, double it again, and you should be set until Microsoft's next blunder (maybe this time next year).

Go bigger than 1000!

Shesh...this is exactly what I was talking about....
JoshBerke
+1  A: 

Here is one that is 257

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.2; .NET CLR 3.0.04506.648; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)

I've seen up to 255 characters so far on a very very low traffic site. So not surprising. .Net 4.0 will probally add another 20 chars as well.
JoshBerke
A: 

How's this for big?:

"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; YPC 3.2.0; SearchSystem6829992239; SearchSystem9616306563; SearchSystem6017393645; SearchSystem5219240075; SearchSystem2768350104; SearchSystem6919669052; SearchSystem1986739074; SearchSystem1555480186; SearchSystem3376893470; SearchSystem9530642569; SearchSystem4877790286; SearchSystem8104932799; SearchSystem2313134663; SearchSystem1545325372; SearchSystem7742471461; SearchSystem9092363703; SearchSystem6992236221; SearchSystem3507700306; SearchSystem1129983453; SearchSystem1077927937; SearchSystem2297142691; SearchSystem7813572891; SearchSystem5668754497; SearchSystem6220295595; SearchSystem4157940963; SearchSystem7656671655; SearchSystem2865656762; SearchSystem6520604676; SearchSystem4960161466; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Hotbar 10.2.232.0; SearchSystem9616306563; SearchSystem6017393645; SearchSystem5219240075; SearchSystem2768350104; SearchSystem6919669052; SearchSystem1986739074; SearchSystem1555480186; SearchSystem3376893470; SearchSystem9530642569; SearchSystem4877790286; SearchSystem8104932799; SearchSystem2313134663; SearchSystem1545325372; SearchSystem7742471461; SearchSystem9092363703; SearchSystem6992236221; SearchSystem3507700306; SearchSystem1129983453; SearchSystem1077927937; SearchSystem2297142691; SearchSystem7813572891; SearchSystem5668754497; SearchSystem6220295595; SearchSystem4157940963; SearchSystem7656671655; SearchSystem2865656762; SearchSystem6520604676; SearchSystem4960161466; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"

cd
For those keeping score, that's 1546 characters, including the leading and trailing quotes.
Doug Harris