Forum Discussion
Fiko_29923
Nimbostratus
Jun 17, 2011insert 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
- hoolio
Cirrostratus
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 - hoolio
Cirrostratus
See the attached text file for an uncorrupted version.
Aaron - Fiko_29923
Nimbostratus
many thanks Aaron, I'll test it out - Fiko_29923
Nimbostratus
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 - Peter_72728
Nimbostratus
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 - hoolio
Cirrostratus
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 - Peter_72728
Nimbostratus
Good catch, Aaron. I missed that!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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