Forum Discussion

mahern_56900's avatar
mahern_56900
Icon for Nimbostratus rankNimbostratus
Nov 11, 2009

Add 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.

5 Replies

  • Hi,

     

     

    It should be possible to either use a STREAM::expression regex to avoid rewriting the content you don't want to or use the STREAM_MATCHED event to modify what is rewritten.

     

     

    Can you clarify what your current STREAM::expression is? The one you have listed doesn't appear in the input parameter you've listed.

     

     

    Aaron
  • The input hidden to avoid is:

     

     

     

     

     

    And the irule code 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  
             }    
          }    
       }
  • 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?

     

     

    Thanks,

     

    Aaron
  • Posted By hoolio on 11/11/2009 11:43 AM

    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?

    Thanks,

    Aaron

    Well, as I noticed, we only need to avoid rewriting and input, although if it's easier not to rewrite all the input parameters, its ok.

    Rewrite example:

     
      target="_self" name="frm" action="/nilo/SvtMontarPaginaComun?clase=certificaciones.AccModificarCertificacion" method="post">

    No rewrite examples (there are more axamples, but all without /nilo, only the urlDestino has the value we replace with the current irule and we dont want to replace).

     
      
      
      
      
     

  • 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?

    Thanks,

    Aaron

     
     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" 
        } 
     }