cancel
Showing results for 
Search instead for 
Did you mean: 

Session Persistence based on http header value using iRule

Mohanad
Cirrostratus
Cirrostratus

Hello

 

Kindly i need to apply Session Persistence based on http header :

 

Payment application working as follow:

 

  1. At first request (Login) the server response with http header named "X-Token" with "fb9c2bb6-80f6-16c3-afcd-84e98976a4b7"
  2. The rest of http requests will have header name "X-Auth-Token" with the same value "fb9c2bb6-80f6-16c3-afcd-84e98976a4b7" assigned by the server

 

I want to make sure that the client land on the same server that sent the "X-Token"

 

I searched for iRule that match the http header, the following iRule will work or need to modify it?

 

when HTTP_REQUEST { if { [HTTP::header exists "X-Auth-Token"]} { persist uie [HTTP::header "X-Auth-Token"] } }

Q

1 ACCEPTED SOLUTION

xuwen
Cirrostratus
Cirrostratus

when HTTP_RESPONSE {

if { [HTTP::header exists "X-Token"] } {

if { [HTTP::header "X-Token"] != "" } {

persist add uie [HTTP::header "X-Token"]

}

}

}

when HTTP_REQUEST {

if { [HTTP::header exists "X-Auth-Token"] } {

set value [persist lookup uie [HTTP::header "X-Auth-Token"]]

log local0. "value is $value"

if { $value != "" } {

persist uie [HTTP::header "X-Auth-Token"]

}

}

}

View solution in original post

5 REPLIES 5

oguzy
Cirrostratus
Cirrostratus

Hi Mohanad,

 

Your irule seems correct. Maybe you can add a fallback persistence in an else condition.

 

According to the article (Overview of universal persistence (f5.com), in addition to your irule, you should also create a universal persistence profile as follows:

To create a universal persistence profile and reference the persistence iRule you created in the previous procedure, perform the following procedure:

  1. Log in to the Configuration utility.
  2. Navigate to Local Traffic > Profiles.
  3. From the Persistence menu, click Create.
  4. Type a name for the universal persistence profile.
  5. For Persistence, click Universal.
  6. For Configuration, select the iRule check box, then click the persistence iRule you created.
  7. Click Finished.

 

 

Thank you Oguzy, i know this requires persistence profile

xuwen
Cirrostratus
Cirrostratus

when HTTP_RESPONSE {

if { [HTTP::header exists "X-Token"] } {

if { [HTTP::header "X-Token"] != "" } {

persist add uie [HTTP::header "X-Token"]

}

}

}

when HTTP_REQUEST {

if { [HTTP::header exists "X-Auth-Token"] } {

set value [persist lookup uie [HTTP::header "X-Auth-Token"]]

log local0. "value is $value"

if { $value != "" } {

persist uie [HTTP::header "X-Auth-Token"]

}

}

}

Thank you so much xuwen, i will test it out and feedback

 

 

working successful! thank you so much xuwen