Forum Discussion

kawiman_43144's avatar
kawiman_43144
Icon for Nimbostratus rankNimbostratus
Jul 25, 2012

Respond to Get request on it's own?

I am evaluating load balancers and one "nice to have" would be to have the load balancer itself respond to an http get request with a specified string to any client that sends the get. Is this possible?

2 Replies

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    Sure. Use an iRule. Just implement the HTTP_REQUEST method, check the URI sent, if it's the specified string, respond to it from the iRule, if not just continue to forward the request as normal.

    e.g. (Sorry, quick cut & paste from another iRUle, but the gist is there. It looks up the URI in a data group and responds with the content (value) if it exists).

    
    when HTTP_REQUEST {
       Retrieve the login form from a base64 encoded external class file
       Pull just the filename from the path... So we need to get rid of the leading '/'.
      set lf_file [substr [HTTP::path] 1]
      if { $lf_debugFlag  >=2 } {
    HSL::send $lfs001hsl "${lfs001HSLPrefix}:: Checking for $lf_file in DG $lf_contentClass"
      }
      
      v9 set lf_ResponseData [findclass $lf_file $::loginForm_test " "]
      set lf_ResponseData [class search -value $lf_contentClass equals "$lf_file"]
      if { $lf_ResponseData ne "" } {  
       There's 2 fields... 
        set lf_MimeType [getfield $lf_ResponseData " " 1]
        set lf_Content [b64decode [getfield $lf_ResponseData " " 2]]
    
        if { $lf_debugFlag  >=2 } {
      HSL::send $lfs001hsl "${lfs001HSLPrefix}:: Serving $lf_MimeType for $lf_file"
        }
     Perform the substitutions...
    if { $lf_MimeType equals "text/html" } {
          regsub -all {} $lf_Content "[IP::client_addr]" lf_Content
        }
     
        HTTP::respond 200 content $lf_Content "Content-Type" "$lf_MimeType"
    
    }
    
    

    H
  • As Hamish said this is definitely possible. Here's a slightly simpler example that sends some HTML in an HTTP 200 response for requests to /respond.html:

    https://devcentral.f5.com/wiki/iRules.http__respond.ashx

    
    when HTTP_REQUEST {
    
    if {[HTTP::path] eq "/respond.html" {
    HTTP::respond 200 content {
    
    
    Apology Page
    
    
    We are sorry, but the site you are looking for is temporarily out of service
    If you feel you have reached this page in error, please try again.
    
    
    }
    }
    }
    

    Aaron