Forum Discussion
Stanislas_Piro2
Dec 14, 2017Cumulonimbus
you can try this code:
In your code, you don't server side http compression. and the stream expression variable is created on every response instead of create it only when the irule is loaded.
when RULE_INIT {
Insert Token Javascript
set jscript {}
Create the stream expression list and insert in this list all rewrite expressions.
set static::stream_expression [list]
lappend static::stream_expression "@@$jscript@"
lappend static::stream_expression "@@$jscript@"
create the extension list to not rewrite
set static::no_rewrite_ext [list ashx asmx axd js]
}
when HTTP_REQUEST {
Check if the word is included in URI and if request extension support javascript insertion.
if {[HTTP::uri] contains "/Anakin" && [lsearch $static::no_rewrite_ext [getfield [URI::basename [HTTP::uri]] "." 2]] == -1 } {
set insertJscript 1
HTTP::header remove "Accept-Encoding"
} else {
set insertJscript 0
}
Disable the stream filter for client requests as we are only interested in the server response
STREAM::disable
}
when HTTP_RESPONSE {
if {$insertJscript && [HTTP::status] == 200 && [HTTP::header value Content-Type] contains "text" && !([HTTP::payload] contains "META HTTP-EQUIV=\"Refresh\"")} {
STREAM::expression $static::stream_expression
STREAM::enable
}
}