Reputation: 1385
I'm trying to a create a fully functional web proxy using node.js which essentially downloads the webpage and displays it to the client. I'm having a problem implementing cookies though as it's harder than I thought since they have so many rules.
Are there any libraries that have been already made to emulate how a browser handles cookies?
Upvotes: 6
Views: 1719
Reputation: 27313
Use request, it already handles storing the cookies for consecutive requests in a cookie jar.
Or if you don't want to reinvent the wheel use node-http-proxy from Nodejitsu for a full blown proxy.
Upvotes: 2
Reputation: 63663
You should really have a look at Tobi's implementation of cookie, here are some useful links:
Cookie and cookie jar:
https://github.com/LearnBoost/tobi/blob/master/lib/cookie/index.js
https://github.com/LearnBoost/tobi/blob/master/lib/cookie/jar.js
Tests for cookie and cookie jar:
https://github.com/LearnBoost/tobi/blob/master/test/cookie.test.js
https://github.com/LearnBoost/tobi/blob/master/test/cookie.jar.test.js
Last but not least, look at the browser file, to see how they are implemented on requests: (look for every occurence of the word "cookie" in that file)
https://github.com/LearnBoost/tobi/blob/master/lib/browser.js
Upvotes: 1