Forum Discussion

daveclarkjr's avatar
daveclarkjr
Icon for Nimbostratus rankNimbostratus
Nov 11, 2016

host replace question with iRule

Is there any way to keep F5VSserver.null.com as the host? Would using HTTP::host be an option?

 

client request

 

https://f5VSserver.null.com/?uri=http://Server1.null.com/xyz/go?app_url=http://Server2.null.com:8000/http_handler/file.htm

 

when HTTP_REQUEST { log local0. "xyz_Forms = [HTTP::uri]"

 

if { [string tolower [HTTP::uri]] contains "xyz" } { set uri [string map -nocase {"/?uri=; "/xyz/"} [HTTP::uri]] log local0. "xyz_new = $uri" HTTP::uri $uri } }

 

http://Server2.null.com:8000/http_handler/file.htm being the final result as expected.

 

  • Vernon_97235's avatar
    Vernon_97235
    Historic F5 Account

    I'm not 100% sure I understand the question, but breaking down the original client request:

    https://f5VSserver.null.com/?uri=http://Server1.null.com/xyz/go?app_url=http://Server2.null.com:8000/http_handler/file.htm
    

    would create an HTTP Request message that looks something like this:

    GET /?uri=http://Server1.null.com/xyz/go?app_url=http://Server2.null.com:8000/http_handler/file.htm HTTP/1.1
    Host: f5VSserver.null.com
    ... other headers here ...
    

    Unless you use a Local Traffic Policy or iRule to modify the Host header, it will remain unchanged as the HTTP Request message is proxied to the selected Pool Member. The only thing your rule is modifying is the Request Target (aka, the Request URI) which is the field immediately after the GET method in the start-line. The requested hostname is not part of the Request Target.

  • I'm not 100% sure I understand the question, but breaking down the original client request:

    https://f5VSserver.null.com/?uri=http://Server1.null.com/xyz/go?app_url=http://Server2.null.com:8000/http_handler/file.htm
    

    would create an HTTP Request message that looks something like this:

    GET /?uri=http://Server1.null.com/xyz/go?app_url=http://Server2.null.com:8000/http_handler/file.htm HTTP/1.1
    Host: f5VSserver.null.com
    ... other headers here ...
    

    Unless you use a Local Traffic Policy or iRule to modify the Host header, it will remain unchanged as the HTTP Request message is proxied to the selected Pool Member. The only thing your rule is modifying is the Request Target (aka, the Request URI) which is the field immediately after the GET method in the start-line. The requested hostname is not part of the Request Target.

  • Ah, so I assume what you really want is to change what comes after app_url= in the Request Query Parameters. Assuming that is the case, you can simply extend the

    string map
    set:

    when HTTP_REQUEST {
        log local0. "xyz_Forms = [HTTP::uri]"
    
        if { [string tolower [HTTP::uri]] contains "xyz" } { 
            set uri [string map -nocase { "/?uri=http://Server1.null.com/xyz/" "/xyz/" "Server2.null.com:8000" "[HTTP::host]" } [HTTP::uri]]
            log local0. "xyz_new = $uri" HTTP::uri $uri 
        } 
    }
    

    That would change this Request Target:

    /?uri=http://Server1.null.com/xyz/go?app_url=http://Server2.null.com:8000/http_handler/file.htm
    

    into this:

    /xyz/go?app_url=http://f5VSserver.null.com/http_handler/file.htm
    

    assuming that the Host header is set to f5VSserver.null.com.