Forum Discussion

Kalyan_Reddy_Da's avatar
Kalyan_Reddy_Da
Icon for Nimbostratus rankNimbostratus
Jul 13, 2010

Can we Insert HTTP Header using HTTP Profile for a dynamic tranaction id generation

Can we Insert HTTP Header using HTTP Profile for a dynamic tranaction id generation.

 

 

Example:

 

 

The following code i am using in my irule to generate a random number for my transaction ID.

 

set ::transactionID [expr { int(10000000 * rand()) }]

 

incr ::transactionID

 

HTTP::header insert TRANSACTID $::transactionID

 

 

Can we achieve the same using http profile Header Insert Option?

 

 

Your help is greatly appreciated

 

2 Replies

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Kalyan,

     

     

    You can use iRule syntax in the HTTP profile header to insert field, but I think it needs to be on a single line:

     

     

    TRANSACTID [incr [expr { int(10000000 * rand()) }]]

     

     

    Aaron
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    I didn't test that first. It results in a runtime error as incr expects a variable--not a number:

     

     

    expr { int(10000000 * rand()) }

     

    4888651

     

     

    incr 1

     

    can't read "1": no such variable

     

     

    Can you try this instead:

     

     

    [expr { int(10000000 * rand()) }]

     

     

    This will generate a random number for each HTTP request. It will not increment a past value, so the ID numbers won't be sequential. If you wanted to store the past value in a global variable, you'd need to use an iRule.

     

     

    Aaron