Get a value of a particular cookie in Socket.io -
I am using socket.io for real time messaging in my application (most applications were not written in node ) I am looking for a way to get the value of special cookies with socket.
The closest I've been using yet: client.request.headers.cookie
which gives me a string: io = Ntp0MJVr3J_ifTKjAAAA; My_sess = c08mk6g0u66ifrjm6madt7535mknb7ur; Other = fk1sq140hgj6gmp1vdcimkto71
.
I am not interested in all these values and only need my_sess, of course I can split and parse the string. This is not the hardest and easiest way:
var value = cookieStr.split ('my_sess =') [1] .split (';') [0];
But before doing so, I will ask if I have a native method to give the cookie value.
You can install - a small module for cookies parsing and serialization:
< If you are using XProp Framework, you can require
cookie module without setting it up. : Var cookie = requires ('Express / node_module / cookie');
Then use it:
var value = cookie Pars (cookiessrr) My_sess;
Comments
Post a Comment