Forum Discussion
fayar_128903
Nimbostratus
Jul 09, 2013Http cookies insertion in LTM
Hello !
I am currently learning how to write iRules. In order to implement a logging script on a LTM device (BigIp V11), I would like to insert a cookie containing a number in my http request. ...
Kevin_Stewart
Employee
Jul 09, 2013If I understand you correctly, you want to set a cookie in the ingress flow to the server for each request, containing some random unique identifier, and then strip it off of the response before sending data to the client so that the client is never involved in the cookie process.
The first thing I'd ask, just out of curiosity, is why? What does this do to/for the web server - considering that the cookie value is NOT user-specific.
The second thing I'd point out is that a web server doesn't natively relay cookies the way a browser would. The presence of a cookie in the output stream will always be a "Set-Cookie" header intended for the browser. The presence of a cookie in the input stream will always be a "Cookie" header from the browser, relaying a previously set cookie. A web server would neither expect a "Set-Cookie" header, nor generally know what to do with it, so you'd need to build in some capability into the application to relay a cookie value back in the response. But while you're at it, and since the client isn't involved in the process anyway, an HTTP header would be generally easier to work with.
An example:
when RULE_INIT {
using the static namespace in v10/11 allows for CMP-compliance
set static::cn "uniqueid"
}
when HTTP_REQUEST {
set unique_id [format %09d [expr {int(rand() * 1e9)}]]
HTTP::header insert $static::cn $unique_id
}
when HTTP_RESPONSE {
if { [HTTP::header exists $static::cn] } {
HTTP::header remove $static::cn
}
}
Then simply code your application to both receive and send HTTP headers instead of cookies.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
