on 18-Mar-2015 11:48
Problem this snippet solves:
This iRule shows how to rewrite an HTTP web application's self references from http:// to https:// to avoid insecure content warnings.
Note if the response content size is changed like it would be with this iRule you must use a custom HTTP profile with response chunking set to rechunk.
Code :
when HTTP_REQUEST { # Save the requested host value set host [string tolower [HTTP::host]] # If the HTTP host header is blank, use the VS IP address # If the VS IP is not routable for clients, hard code a routable IP # to replace [IP::local_addr] if {$host eq ""}{set host [IP::local_addr]} # Disable the stream filter by default STREAM::disable } when HTTP_RESPONSE { # Check if response type is text and host isn't null if {[HTTP::header value Content-Type] contains "text" and $host ne ""}{ # Replace http://$host with https://$host STREAM::expression "@http://$host@https://$host@" # Enable the stream filter for this response only STREAM::enable } # Rewrite the Location header in redirects to https:// if { [HTTP::is_redirect] && [string tolower [HTTP::header Location]] starts_with "http://$host"} { HTTP::header replace Location [string map -nocase "http://$host https://$host" [HTTP::header Location]] } }
If you get errors from browser about XMLHttpRequest response server being send over http.
Error message might be : Mixed Content: The page at 'https:/xxxx.com/zzz.html' was loaded over HTTPS, but requested an insecure resource 'http://xxxx.com/b/ttt.css'. This request has been blocked; the content must be served over HTTPS."
Make sure you assign a compression profile to the VS that runs this irule.
This is because STREAM function requires that server response to be decompressed before hand.
Hello Hoolio. I used the irule after application owner was getting a 'Blocked loading mixed active content" on his webpage.
However,after applying the Your irule, i get error https://agilitycareuat.kazeem.com.ng:80/UserManagement/com/ericsson/usermanagement/userlogin/fetchLo....
It appends a port 80,after making a request with test user "testuser1". If however,i remove the port 80. The request goes fine.
What is the solution to this?