how to clear a cookie value in request object

Michael Ellery mellery451 at
Fri Nov 1 16:41:20 UTC 2013


I'm looking for advice about how to properly clear a cookie value from the current request so that it will be omitted
from the request when it goes upstream (to proxy). Here's the code I currently have:

        static ngx_str_t my_cookie_name = ngx_string("MyMagicCookieName");

        ngx_uint_t         i;
        ngx_table_elt_t  **h;
        ngx_str_t  null_header_value = ngx_null_string;
        h = r->headers_in.cookies.elts;
        for (i = 0; i < r->headers_in.cookies.nelts; i++) {
            if (h[i]->value.len > my_cookie_name.len &&
                0 == ngx_strncmp(h[i]->,, my_cookie_name.len))
                h[i]->value = null_header_value;

my main concern is leaking memory -- will the nulling of this value cause memory to be leaked? If so, how can I fix this?

A secondary concern is that I believe value can actually contain a list of comma separated of cookie name/vals, although
I've not actually encountered that problem so far. What would be the right way to wipe out only PART of the value data,
if that's indeed what I need to do?

Mike Ellery

More information about the nginx-devel mailing list