Forum Discussion
mahern_56900
Nimbostratus
Nov 11, 2009Add exception to response rewrite
Hi,
We are using the following irule to rewrite the headers and body of an old application:
when HTTP_REQUEST {
initialize a var
set check_response 0
Check if path starts with the correct text
if {[HTTP::uri] starts_with "/word"} {
set check_response 1
}
}
when HTTP_RESPONSE {
Check if we write in the correct header
if {$check_response}{
Check if JSESSIONID is present
if {[HTTP::cookie exists JSESSIONID]}{
Replace JSESSIONID path
HTTP::cookie path JSESSIONID "/path/word"
}
Check if request is text
if {[HTTP::header value Content-Type] contains "text"} {
Set text to change and enable stream filter
STREAM::expression {@/word/@/path/word/@}
STREAM::enable
} else {
If not text, disable stream filter
STREAM::disable
}
}
}
But we need to avoid modifying the hidden html code of the body:
¿Is it possible?
Thanks in advance.
- hoolio
Cirrostratus
Hi, - mahern_56900
Nimbostratus
The input hidden to avoid is:when HTTP_REQUEST { Inicializamos una variable para comprobar si tenemos que reescribir las cabeceras/contenido set check_response 0 Comprobamos si el path es el que buscamos if {[HTTP::uri] starts_with "/nilo"} { Ponemos la variable a 1 para actuar en las cabeceras/contenido set check_response 1 } } when HTTP_RESPONSE { Comprobamos que no escribimos una cabecera que no debemos if {$check_response}{ Comprobamos si la cookie JSESSIONID existe if {[HTTP::cookie exists JSESSIONID]}{ Establecemos el path de la cookie a /sdr/nilo HTTP::cookie path JSESSIONID "/sdr/nilo" } Comprobamos si la peticion es text if {[HTTP::header value Content-Type] contains "text"} { Establecemos el texto a reemplazar y activamos el filtro stream STREAM::expression {@/nilo/@/sdr/nilo/@} STREAM::enable } else { En las respuestas que no son text, desactivamos el filtro stream STREAM::disable } } }
- hoolio
Cirrostratus
That might be a bit trickier than I thought originally. Do you want to not rewrite any input parameter in the response content? What is the context for other strings are you trying to rewrite? Can you provide a few examples of strings you do want to rewrite and a few examples of strings you don't want to rewrite? - mahern_56900
Nimbostratus
Posted By hoolio on 11/11/2009 11:43 AM
target="_self" name="frm" action="/nilo/SvtMontarPaginaComun?clase=certificaciones.AccModificarCertificacion" method="post">
- hoolio
Cirrostratus
If you're able to not rewrite any input parameter, it should be a little easier. I haven't this fully, but the regex seems to work in some quick checks. If you see any issues with this, can you reply with the log output from /var/log/ltm?when HTTP_REQUEST { Inicializamos una variable para comprobar si tenemos que reescribir las cabeceras/contenido set check_response 0 Comprobamos si el path es el que buscamos if {[HTTP::uri] starts_with "/nilo"} { Ponemos la variable a 1 para actuar en las cabeceras/contenido set check_response 1 } } when HTTP_RESPONSE { Comprobamos que no escribimos una cabecera que no debemos if {$check_response}{ Comprobamos si la cookie JSESSIONID existe if {[HTTP::cookie exists JSESSIONID]}{ Establecemos el path de la cookie a /sdr/nilo HTTP::cookie path JSESSIONID "/sdr/nilo" } Comprobamos si la peticion es text if {[HTTP::header value Content-Type] contains "text"} { Establecemos el texto a reemplazar y activamos el filtro stream STREAM::expression {@/nilo/@/sdr/nilo/@} STREAM::enable } else { En las respuestas que no son text, desactivamos el filtro stream STREAM::disable } } } when STREAM_MATCHED { log local0. "[IP::client_addr]:[TCP::local_port]: Matched: [STREAM::match]" Only rewrite /nilo/ to /sdr/nilo/ if the matched string is not an input parameter Check if matched string does not start with if {not ([string tolower [STREAM::match]] starts_with " Replace /nilo/ with /sdr/nilo/ in the matched string and use that for the replacement STREAM::replace "[string map {/nilo/ /sdr/nilo/} [STREAM::match]]" log local0. "[IP::client_addr]:[TCP::client_port]: Matched: [STREAM::match], replaced with: [string map {/nilo/ /sdr/nilo/} [STREAM::match]]" } else { Prevent replacement from being performed by calling STREAM::replace with no value STREAM::replace log local0. "[IP::client_addr]:[TCP::client_port]: Matched: [STREAM::match], but did not perform replacement" } }
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