Forum Discussion

Andrea's avatar
Andrea
Icon for Nimbostratus rankNimbostratus
Jan 05, 2016

can big-ip intercepted a redirect

Is it possible to intercept a redirect transparently to the client. keeping the original GET from the URL

 

4 Replies

  • Hi Andrea,

     

    if I understand your question correctly, then you're looking for a solution to...

     

    1. Intercept a redirect response send from your pool servers to your clients?

       

    2. Request the location specified in the redirect response on behalf of your clients?

       

    3. Forward the received response to your clients?

       

    Is this correct?

     

    Cheers, Kai

     

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    Sure is... You just need to attach an iRule to the VS and trigger on the HTTP_RESPONSE event and read the location header. Then you can do what you like with it (Log it via HSL... send it somewhere... etc)

     

    Or you could use an HTTP logging profile if all you want to do is log it (IIRC logging profiles came in around 11.4 so you'd need to be running at least that level to use one)...

     

    H

     

  • Hi Andrea,

    you may want to use this PoC code as a starting point...

     

    when RULE_INIT { 
        set static::local_url "https://www.itacs.de"
        set static::local_url_length [string length $static::local_url]
    }
    when HTTP_REQUEST { 
        set temp(http_request) [HTTP::request]
        set temp(orig_uri) [HTTP::uri]
    }
    when HTTP_RESPONSE { 
        if { [HTTP::is_redirect] } then {
            set temp(redir_uri) [HTTP::header value Location]
            if { ( $temp(redir_uri) starts_with "/" ) } then {
                log -noname local0.debug "Following [HTTP::status] HTTP redirect from \"$temp(orig_uri)\" to \"$temp(redir_uri)\""
                HTTP::retry [string map [list " $temp(orig_uri) HTTP/" " $temp(redir_uri) HTTP/"] $temp(http_request)]
            } elseif { $temp(redir_uri) starts_with $static::local_url } then {
                log -noname local0.debug "Following [HTTP::status] HTTP redirect from \"$temp(orig_uri)\" to \"[string range $temp(redir_uri) $static::local_url_length end]\""
                HTTP::retry [string map [list " $temp(orig_uri) HTTP/" " [string range $temp(redir_uri) $static::local_url_length end] HTTP/"] $temp(http_request)]
            }
        }
        unset -nocomplain temp
    }
    

     

    The outlined iRule stores your initial [HTTP::request] and [HTTP::uri] during HTTP_REQUEST event and then listens for 301/302 redirect responses during HTTP_RESPONSE event. If the redirect responses are relational to your www-root /* or matching the configured $static::local_url then [HTTP::retry] will be executed using the data of your initial [HTTP::request] but with changed [HTTP::uri] informations.

    Cheers, Kai