Forum Discussion

yo-digitales's avatar
yo-digitales
Icon for Nimbostratus rankNimbostratus
Sep 26, 2019

irule + regex

Hi All,

 

New to F5 and irules in general.

 

We have a situation where we need to grab a portion of the HTTP Post that come into the BIGIP, Look for string, and send a manipulated HTTP Post to the Pool.

 

 

My thought was to use Regexp to grab the needed potion of the URL, put that into a variable, then create a new HTTP POST and send it to the specified Pool.

 

Any thoughts or advice? or example scripts I can view/modify

 

 

Example:

 

Initial HTTP POST: https://example.com/-payload/somefile.html

 

Regex grabs the payload and put it into a var.

 

Modified HTTP Post that needs to go to the Pool will look like this : https://payload.example.com/somefile.html

 

 

 

  • Hi yo-digitales,

    I hope these codes will help you.

    when HTTP_REQUEST {
    	log local0. "old-host = [HTTP::host]"
    	log local0. "old-path = [HTTP::path]"
    	
    	set pathfirstdir [getfield [HTTP::path] "/" 2]
    	log local0. "path-first-dir = $pathfirstdir"
    	
    	set newpath [string map -nocase [list /$pathfirstdir ""] [HTTP::path]]
    	log local0. "new-path = $newpath"
    	
    	set newhost "$pathfirstdir.[HTTP::host]"
    	log local0. "new-host = $newhost"
    	
    	set newaddress "https://$newhost$newpath"
    	log local0. "new-address = $newaddress"
    }