reading cookie value issue

Pankaj Chaudhary pankajitbhu at gmail.com
Tue Apr 26 11:37:19 UTC 2016


Hi,

I have requirement to create own cookie  based on input  and wirte the that
cookie in header.
whenever i need that i can read from header and use it.


for example:-

I have created my own cookie "thissomevalue" worte in header and later the
same read from header.

Please check my code and let me know why i am not able to read the value
from header.

Below code snippet to set header value in request header:-

ngx_table_elt_t *cookie;
cookie = ngx_list_push(&r->headers_in.headers);
cookie->lowcase_key = (u_char*) "cookie";
ngx_str_set(&cookie->key, "Cookie");
ngx_str_set(&cookie->value, "somevalue");
cookie->hash = ngx_crc32_long(cookie->lowcase_key, cookie->key.len);


Below code snippet to read set value from header:-

ngx_http_core_main_conf_t   *clcf;
ngx_str_t                   *type;
ngx_uint_t                   key;
ngx_str_t    val = ngx_string("cookie");
clcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
key= ngx_hash_key_lc(val.data, val.len);
type = ngx_hash_find(&clcf->headers_in_hash, key,  val.data, val.len);

if (type != NULL)
{
ngx_table_elt_t *test_val;
test_val= ngx_list_push(&r->headers_out.headers);
test_val->lowcase_key = (u_char*) "test_val";
ngx_str_set(&test_val->key, "Test_Val");
ngx_str_set(&test_val->value, type->data);
test_val->hash = ngx_crc32_long(test_val->lowcase_key, test_val->key.len);
}

curl response:-Test_val was accepting "somevalue"
HTTP/1.1 200 OK
Server: nginx/1.9.12
Date: Tue, 26 Apr 2016 19:13:40 GMT
Content-Type: text/plain
Content-Length: 34
Connection: keep-alive
Test_Val: Cookie

Hello, This is Nginx test Module!

Thanks & Regards,
Pankaj Chaudhary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20160426/af20a22f/attachment.html>


More information about the nginx-devel mailing list