Forum Discussion

Patrez_70317's avatar
Patrez_70317
Icon for Nimbostratus rankNimbostratus
Sep 16, 2016

Hash persistence based on substring in URI

Hello, I am looking for a way how to implement persistence based on UID that is in URI. Here is the example URI: /v1/projects/f12876fe-1b1c-4e5b-80d1-7e40929d72d3/iou/vms

 

The bold part will be different for each project and based on this UID in URI I would need to secure persistence to one server from pool.

 

Can someone help me prepare iRule that could achieve what I want?

 

Thanks

 

1 Reply

  • Hi Patrez,

    you may try the snippet below...

    when HTTP_REQUEST {
        if { ( [HTTP::path] starts_with "/v1/projects/" ) and ( [set uie [getfield [HTTP::path] "/" 4]] ne "" ) } then {
            persist carp $uie
        } else {
            persist none
        }
    }
    

    Note: The provided script uses the stateless CARP algorythm to distribute and track persistence. You may change it to

    persist hash $uie [lifetime in seconds]
    if you want to have a stateful persistence tracking.

    Note: Also keep in mind to attch a OneConnect Profile to your Virtual Server if a single users is accessing multiple projects using the same browser session. This will allow your LTM to rebalance each request to the right pool member.

    Cheers, Kai