Forum Discussion

darragh_19954's avatar
darragh_19954
Icon for Nimbostratus rankNimbostratus
Nov 14, 2007

Can global variables be used to carry information between events?

I'd like to use a global variable set up in the RULE_INIT event to carry some client-specific conditional information between the HTTP_REQUEST and HTTP_RESPONSE events. Is this possibe>

 

 

Here is the pseudo-code:

 

 


when RULE_INIT {
set ::variable 0
}
when HTTP_REQUEST {
 conditional 
if { ... } {
set ::variable 1
} elseif { ... } {
set ::variable 2
} ...
}
when HTTP_RESPONSE {
switch $::variable {
1 { ... }
2 { ... }
3 { ... }
default { ... }
}
}

 

 

So if 2 clients make a request at the same time, and they each have different settings for this variable, will those client-specific settings be preserved when the HTTP_RESPONSE event is called for each?

2 Replies

  • Global variables are accessible across all TCP connections and all events. Local variables are accessible across all events of a single TCP connection.

     

     

    If don't want the values to be trampled by different connections/clients, you should only use a local variable. A local variable set in one event will be available for that connection across all other events. You can set the default value for a local variable when the TCP connection is established in the CLIENT_ACCEPTED event.

     

     

    Aaron