Forum Discussion

Fiko_29923's avatar
Fiko_29923
Icon for Nimbostratus rankNimbostratus
Jun 17, 2011

insert javascript to html pages using irules

Hi, I want to ask is it possible to insert javascript to existing web pages?

 

e.g. I have web pages which already running and use it as pool member for load balancing. Using iRules, I want to check for incoming HTTP request thus when request comes will fire irules and insert javascript into the web page.

 

 

Anyone can help me with this problem?

 

7 Replies

  • Hi Fiko,

    Here's an untested example to start with. It requires a blank stream profile and a custom HTTP profile with response chunking set to rechunk be added to the virtual server.

    when HTTP_REQUEST {
        Disable stream filter by default
       STREAM::disable
        Don't allow response data to be chunked
       if { [HTTP::version] eq "1.1" } {
           Force downgrade to HTTP 1.0, but still allow keep-alive connections.
           Since HTTP 1.1 is keep-alive by default, and 1.0 isn't,
           we need make sure the headers reflect the keep-alive status. 
          if { [HTTP::header is_keepalive] } {
            HTTP::header replace "Connection" "Keep-Alive"
          }
       }
    }
    when HTTP_RESPONSE {
       if {[HTTP::header Content-Type] starts_with "text/"} {
           Remove the spaces before and after head in < head >
          STREAM::expression {@< head >@@}
          STREAM::enable
       }
    }
    when STREAM_MATCHED {
        Once we've hit one match, disable the stream filter for the rest of the response
       STREAM::disable
    }
    Aaron
  • See the attached text file for an uncorrupted version.

     

     

    Aaron

     

  • Hi, I have some concern regarding connection which enter the BIG-IP and trigger the irule

     

     

    I'm using variable for the url and in response event will check the url and insert javascript.

     

    The problem is when more than one connection occurs at the same time. How the variable will be set?

     

    I know there will be time difference even only 0.0001 or so but in this case what if both connection enter virtual server at the same time. Does it will effect the variable set or not?

     

     

    i modified the irule into this

     

     

    when HTTP_REQUEST {

     

    set ::url [HTTP::host][HTTP::uri]

     

    }

     

     

    when HTTP_RESPONSE {

     

    if { $::url equals "192.168.0.202/index.jsp" } {

     

    STREAM::expression "change page content here";

     

    STREAM::enable;

     

    }

     

    }

     

     

    when STREAM_MATCHED {

     

    STREAM::disable

     

    }

     

     

    or is there any other way to check the url in response without using variables?

     

     

     

     

    thanks
  • From what I understand, that shouldn't be a problem. These devices are designed to handle many concurrent requests. The variable will be set correctly since it's scope is based on the connection.

     

     

    http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/12361/showtab/groupforums/Default.aspx
  • As Peter said if you use a local variable you won't have to worry about trampling of variable values between connections. However, you're using $::url which is a global variable. This will get overwritten each time it is set for each connection. You should change $::url to $url to avoid this issue.

     

     

    Aaron