Search
Colin Walker - Bettering Applications by Network Wizardry
You are here: DevCentral > Weblogs

posted on Friday, November 21, 2008 8:06 AM

What could you do with your code in 20 Lines or Less? That's the question (almost) I ask every week, and every week I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting in over your head.

This week I bring you some more groovy examples of the power that iRule can bring to the table in just a few short lines of code. We'll touch on Protocol specific header insertion, port re-writing, and configuring partial gets properly for PDF reading.  Many thanks to the awesome forum and CodeShare contributors that keep on adding these great examples.

 

Disable Partial Get Requests for Ram Cache

http://devcentral.f5.com/wiki/default.aspx/iRules/Disable_Partial_Get_Requests_For_Ram_Cache.html

Partial Get requests are normally a good thing, but in some cases, as with PDFs, it can hinder the way things operate and throw a wrench in the works.  This tiny little iRule can make sure that your cached PDFs aren't subject to this behavior.

when CACHE_RESPONSE {
  if { [HTTP::uri] ends_with ".pdf" } {
    HTTP::header remove "Accept-Ranges"
  }
}

 

Changing HTTP Header Host and Port

http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=29952&view=topic

It's hoolio to the rescue yet again with a cool example of how to get rid of a custom port in the HTTP host header, as well as re-writing the Location info just to be sure the server isn't trying to undo our hard work.

when HTTP_REQUEST { 
    # Check if host value has a colon 
    if {[HTTP::host] contains ":"}{ 
       # Replace host header value with everything before the colon 
       HTTP::header replace Host "[getfield [HTTP::host] : 1]" 
    log local0. "[IP::client_addr]:[TCP::client_port]: Replace original host [HTTP::host] with [getfield [HTTP::host] : 1]" 
    } 

when HTTP_RESPONSE {
   # Check if response is a redirect
   if {[HTTP::is_redirect]}{
      # Replace :55555/ with / in the Location header
      HTTP::header replace Location [string map {:55555/ /} [HTTP::header value Location]]
   }
}

 

Protocol based header insert

http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=29816&view=topic

This is a neat idea that I can't recall seeing recently, so I thought I'd share.  This user wanted to be able to check what protocol was in use for the transaction in question, and then based on that insert some specific information into a header. With iRules, you can.

when HTTP_REQUEST {
  if { [TCP::local_port] == 443 } {
    HTTP::header insert SSL 1
  } else {
    HTTP::header insert SSL 0}
  }
}

 

There's another 20LoL for you to sink your teeth into.  These brief examples of what iRules can do are great to keep in your back pocket. You never know when you're gonna need 'em. ;)


#Colin


Posted In: iRules, DevCentral,

Feedback

No comments posted yet.

Let Me Know What You Think


Please use the form below if you have any comments, questions, or suggestions.

Title:
 
Name:
 
Email: (so we can show your gravatar)
Website:
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
 
Please add 7 and 6 and type the answer here:

Blog Stats

Posts:221
Comments:77
Stories:0
Trackbacks:0
  

Games, Gaming, etc.

  

IT News and Info

  

Misc.

  

Add to Technorati Favorites

82,243 Members in 102 Countries and Growing!

Join DevCentral Today!

About DevCentral

DevCentral has been a successful, thriving community for many years. We have always strived to bring you the best technical documentation, discussion forums, blogs, media and much more that we can.

So dive in, get familiar with DevCentral. We hope you like it, we hope it makes your job easier, and lets you get that much more power out of the community. To learn more, make sure to check out the Getting Started section. And if you have any problems, or think something could be easier to use, drop us a line to let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback       or