Forum Discussion

yunan_haris_123's avatar
yunan_haris_123
Icon for Altostratus rankAltostratus
Jan 21, 2016

irule for change the url and port

dear all

 

i have customer who had proxy before, and the ideas is change the function of the proxy. unfortunately i think we must use irule to do that. here are the requirement :

 

  1. we need to replace the http with https, also if it contains port 8080 in the URL we must remove it. i dont know whether it used on the http response or request

     

  2. they need to edit http response content/body, if mime type are application/excel text/html text/plain, they need subtitute the http to https and remove port 8080

     

i hope all of you can help me solving this problem

 

thank you

 

1 Reply

  • Did you try to find if the application server provide a solution to reply with the expected urls?

    Most of application servers include the ability to define http proxy parameters:

    I already did it with :

    • tomcat (proxy host / proxy port)
    • webspere (trusthostheaderport = true + com.ibm.ws.webcontainer.extractHostHeaderPort = true)
    • drupal
    • sharepoint (Alternate acess mapping)

    With these applications, changing request headers (X-Forwarded-proto, Host, ...) permit to not rewrite responses.

    Another solution is to use a rewrite profile (since version 11.4) and define :

    • direction : response
    • client side url:
    • server side url:

    This solution will not rewrite excel content.

    The last solution with irule is:

    when HTTP_REQUEST {
         Disable the stream filter for requests
        STREAM::disable
    
         Remove this header to prevent server from compression response
        HTTP::header remove Accept-Encoding
    }
    when HTTP_RESPONSE {
         Rewrite the Location header for redirects 
        if { [HTTP::header exists Location] }{ 
            HTTP::header replace Location [string map {"http://abc.company.com:8010" "https://abc.company.com"} [HTTP::header Location]] 
        } 
    
         Rewrite the response content using a stream profile if it is text 
        if { [HTTP::header Content-Type] contains "text" } { 
    
             Set the stream expression with the find/replace strings 
            STREAM::expression "@http://abc.company.com:8010@https://abc.company.com@" 
    
             Enable the stream filter 
            STREAM::enable 
        } 
    }