Forum Discussion

Charlie_2_10323's avatar
Charlie_2_10323
Icon for Nimbostratus rankNimbostratus
May 15, 2009

HTTP Respond Data replacing ?

Hi

 

 

I will rewrite response hostname.

 

HTTP_Response function well, but HTTP_Respond_Data not.

 

 

We have on Request and Respond site HTTPS access

 

Client is terminated by Big-IP

 

Also we get HTTPS response it is possible to replacing hppts_response_data?

 

Does someone know that? Or is my http_response_data fools?

 

Any help would be great.

 

 

 

 

when HTTP_RESPONSE {

 

HTTP::collect [HTTP::header Content-Length]

 

if { $target_pool == "blo.server" } {

 

set location [HTTP::header value Location]

 

log local0.info "Server-RESPONS"

 

HTTP::header replace Location [string map -nocase {"blo.server.com" "www.client.com"} [HTTP::header Location]]

 

log "BEFORE Replacing payload with new data."

 

}

 

}

 

when HTTP_RESPONSE_DATA {

 

set clen [string length [HTTP::payload]]

 

regsub -all "blo.server.com" [HTTP::payload] "www.client.com" newdata

 

log "Replacing payload with new data."

 

HTTP::payload replace 0 $clen $newdata

 

HTTP::release

 

}

 

 

4 Replies

  • Hi Charlie,

     

    I am sorry but I don't seem to understand your question(s). Can you re-descibe what you would like to accomplish with our assistance more clearly?

     

     

    CB

     

  • You may want to check this thread:

     

    http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=32434&view=topic

     

     

    I had to use the 1MB workaround in the HTTP_RESPONSE, but found the HTTP::version change in the HTTP_REQUEST did not work for my particular application, so just left it out.

     

     

    Also, I never got the string map stuff to work so used the regsub as shown in the example. (I am still running 9.2.5 on this particular BIGIP)

     

     

  • Hello, chbhatt & tarsier

     

     

    I'm trying to find a way with an iRule (or any functionality really) to take a url like

     

    https://blo.client.com/rk

     

    https://blo.client.com/rk-admin/

     

    and convert it to

     

    https://blo.server.com/rk/index.htm

     

    https://blo.server.com/rk/login.htm

     

     

    as it goes through the bigip (running v9).

     

    The catch is we cannot redirect the browser client to the blo.server.com/rk/index.htm site, the end user must always see blo.client.com.

     

    To make it even more complicated, sometimes the server will send back a payload with a URL inside it for the user that we need to change from blo.server.com to blo.client.com .

     

     

    when HTTP_REQUEST {

     

    log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]"

     

    switch "[string tolower [HTTP::host][HTTP::uri]]" {

     

    "blo.client.com.ch/rk-admin/" {

     

    HTTP::header replace "Host" "blo.server.com"

     

    HTTP::uri "/rk/login.htm"

     

    set target_pool "blo.server"

     

    pool blo.server

     

    log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::host] [HTTP::uri] Rewrite host/uri (1)"

     

    }

     

    "blo.client.com/rk/" {

     

    HTTP::header replace "Host" "blo.server.com"

     

    HTTP::uri "/rk/index.htm"

     

    set target_pool "blo.server"

     

    pool blo.server

     

    log local0. "[IP::client_addr]:[TCP::client_port]: Rewrite host/uri (2)"

     

     

    }

     

    }

     

    }

     

    when HTTP_RESPONSE {

     

    HTTP::collect [HTTP::header Content-Length]

     

    if { $target_pool == "blo.server" } {

     

    set location [HTTP::header value Location]

     

    log local0.info "Server-RESPONS"

     

    HTTP::header replace Location [string map -nocase {"blo.client.com" "blo.serve.com"} [HTTP::header Location]]

     

    log "BEFORE Replacing payload with new data."

     

    }

     

    }

     

    when HTTP_RESPONSE_DATA {

     

    set clen [string length [HTTP::payload]]

     

    regsub -all "blo.client.com" [HTTP::payload] "blo.server.com" newdata

     

    log "Replacing payload with new data."

     

    HTTP::payload replace 0 $clen $newdata

     

    HTTP::release

     

    }

     

     

     

    if is the backend server http (cleartext) this irull is running well, but when I try to change httpS- httpS respond HTTP_response_data it does not function.

     

    Is there a way to do this?

     

     

    Thanks for any help.

     

     

  • It would be more efficient to use a stream profile and iRule to rewrite the response content compared with collecting the response payload. Here is a generic (untested) example. You could add your request URI rewriting logic to it.

    Aaron

     
      LTM configuration object requirements: 
      
      - The virtual server must have an HTTP profile configured 
      - The virtual server must have a blank STREAM profile configured 
      - The virtual server must have a default pool configured 
      
      iRule configuration requirements: 
      
      - Debug can be enabled/disabled in the RULE_INIT event by setting ::rewrite_debug to 1 or 0 respectively. 
      - Outside the RULE_INIT section, no other changes should need to be made. 
      
     when RULE_INIT { 
      
         Log debug messages to /var/log/ltm? 1=yes, 0=no 
        set ::rewrite_debug 1 
      
         String to find in response headers and/or data 
        set ::find "oldname.example.com" 
      
         String to replace in response headers and/or data 
        set ::replace "newname.example.com" 
     } 
     when HTTP_REQUEST { 
      
        if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::host][HTTP::uri]"} 
      
        HTTP::header remove "Accept-Encoding" 
        if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Removing Accept-Encoding request header"} 
     } 
     when HTTP_RESPONSE { 
      
         Rewrite Location header value in HTTP redirects if it contains the $::find string 
           if {[HTTP::is_redirect] && [string tolower [HTTP::header "Location"]] contains $::find}{ 
      
               Replace $::find with $::replace in Location header value 
              HTTP::header replace Location [string map "$::find $::replace" [HTTP::header replace Location]] 
      
              if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Updated location from [HTTP::header replace Location]\ 
                 to [string map "$::find $::replace" [HTTP::header replace Location]]"} 
           } 
      
            Rewrite the response body if the response type is text 
           if { [HTTP::header "Content-Type"] starts_with "text/" } { 
      
               Configure the find/replace strings 
              STREAM::expression "@$::find@$::replace@" 
      
               Enable the stream filter 
              STREAM::enable 
      
              if {$::rewrite_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Enabled stream filter for $::find -> $::replace"} 
      
           } else { 
      
               Disable the stream filter for non-text responses 
              STREAM::disable 
           } 
        } 
     }