-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle cookies #82
Comments
What I really want is an option that just sets and handles cookies the way the browser does. Unfortunately the existing cookie libraries weren't working for me and I had to put that feature on the back burner. -Mikeal On Sep 27, 2011, at September 27, 20114:22 AM, Julien Guimont wrote:
|
What libraries did you look at? |
+1 |
juggy -- care to share your cookie changes to request? i'll take hacks! +1 on callback support to twiddle with headers or cookies support. |
Here's a patch that adds cookie support. Warning, js and node.js and git and github and http newbie here. It works for my application, but no idea if it is per spec. Depends on node-cookiejar, which means package.json should be updated. From 4bf36075d354dd5c41f1598249bf05a161da0cc2 Mon Sep 17 00:00:00 2001 main.js | 8 ++++++++ diff --git a/main.js b/main.js
|
@waynelee Good but you might do the initial request with cookies, use those cookies for the redirection and, finally, se them after the redirection. My code is similar but you have a callback when the redirection occurs where you can do whatever you want (including cookies). |
this is the API i want for cookies var j = request.jar()
r({url:'http://www.google.com', jar:j}, function () {
r({url:'http://images.google.com', jar:j})
}) The jar holds the state of the cookies being set, each request sends the proper cookies for that domain. The boiler is easy to get rid of with var j = request.jar()
var r = request.defaults({jar:j})
request('http://www.google.com', function () {
request('http://images.google.com')
}) |
It looks like https://github.com/bmeck/node-cookiejar might be a good candidate for this API? @alessioalex - Do you want to try looking into this and seeing what you can do? |
if we go with node-cookie jar please check the dependency. i do not want to add dependencies to the package.json if at all avoidable. |
I'll take a look over the weekend on https://github.com/bmeck/node-cookiejar/blob/master/cookiejar.js + https://github.com/LearnBoost/tobi/blob/master/lib/cookie/jar.js and try to come up with a useful implementation |
I think you can solve this without actually adding any specific code for cookies. When you do your request/redirect, a callback can be called to let the user deal with the headers/cookies. No new dependencies would be needed and it would be a little more future proof. As a user of request, if I need cookies, I use any of the available libs to do that (or deal with them myself). A wiki page or a code exemple should be available to ease the implementation. What do you think? |
@juggy I did this, its a pain |
I have this almost 90% implemented, no dependencies needed, I'll finish it in one hour or so and then make a pull request. Bear with me :) |
What's up about this issue, guys? I have the same problem. |
this got merged forever ago. |
Implemented cookies - closes issue 82: request/request#82
I stumbled upon a page that set cookies in the redirection. I don't know if it is part of the http spec or not, but I had to change the redirection code within request to handle this.
Since request does not handle cookies itself, it might make sense to build a generic callback where the caller can play with the headers etc.
Thanks,
Julien.
Mikeal changed the title to add more generic support for cookies.
The text was updated successfully, but these errors were encountered: