Forum Discussion
Javon_Simons_47
Nimbostratus
Jan 06, 2009irule User Agent rewrite
IE problem. It seems that the more .NET updates that you install, the longer your user agent becomes in your registry. I was wondering if this irule would rewrite, IE shorten the user agent:
...
hoolio
Cirrostratus
Jan 06, 2009Out of curiosity, why are you trying to trim down the length of the User-Agent header? Does your app not handle the long header value? Could you just truncate it or replace it with a default value if the User-Agent header is over a certain length and contains ".net clr"?
If not, you could use a regex to replace .net clr followed by the version string.
'HTTP::header replace' expects the header name and the new value for the header in the following format: 'HTTP::header replace header_name new_value'.
when HTTP_REQUEST {
Rewrite the User-Agent header value if it's over 100 characters and contains .NET CLR
if { [string length [HTTP::header "User-Agent"]] > 100 && [string tolower [HTTP::header "User-Agent"]] contains " .net clr"}{
Replace the User-Agent header with a default value
HTTP::header replace "User-Agent" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1; )"
A more precise option (but also more resource intensive)
Replace the .NET CLR strings in the User-Agent header with nothing, using a regex
HTTP::header replace "User-Agent" [regsub -all -nocase {\.net clr (?:\d{1,5}\.?){1,4};? ?} [HTTP::header "User-Agent"] ""]
}
}
Here is a description of the regex:
\.net clr (?:\d{1,5}\.?){1,4};? ?
Match the character "." literally «\.»
Match the characters "net clr " literally «net clr »
Match the regular expression below «(?:\d{1,5}\.?){1,4}»
Between one and 4 times, as many times as possible, giving back as needed (greedy) «{1,4}»
Match a single digit 0..9 «\d{1,5}»
Between one and 5 times, as many times as possible, giving back as needed (greedy) «{1,5}»
Match the character "." literally «\.?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match the character ";" literally «;?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Match the character " " literally « ?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects