views:

525

answers:

2

Hi folks,

NodeJS is a fantastic tool and blazing fast.

I'm wondering if HTTPClient supports cookies and if can be used in order to simulate very basic browser behaviour!


Help would be very much appreciated! =)


EDIT:

Found this: node-httpclient (seems useful!) not working!

+1  A: 

Just get cookies from SetCookie param in response headers and send them back with future requests. Should not be hard.

Kuroki Kaze
A: 

Short answer: no. And it's not so great.

I implemented this as part of npm so that I could download tarballs from github. Here's the code that does that: http://github.com/isaacs/npm/blob/master/lib/utils/fetch.js#L52-56

It's got a lot of npm-specific stuff (log, set, etc.) but it should show you the general idea. Basically, I'm collecting the cookies so that I can send them back on the next request when I get redirected.

I've talked with Mikeal Rogers about adding this kind of functionality to his "request" util, complete with supporting a filesystem-backed cookiejar, but it's really pretty tricky. You have to keep track of which domains to send the cookies to, and so on.

This will likely never be included in node directly, for that reason. But watch for developments in userspace.

isaacs