joepie91 / node-bhttp

A sane HTTP client library for Node.js with Streams2 support.
62 stars 12 forks source link

How to save and load bhttp.session? #44

Open mirgorodalexander opened 4 years ago

mirgorodalexander commented 4 years ago

Hi guys, please can you tell me how I can save and load bhttp.session? I mean bhttp.session() where I authorized in some web site. Thanks!

joepie91 commented 4 years ago

Hi, there's currently no functionality to do this directly in bhttp.

However, this sort of usecase is what the cookieJar option is meant for; you can create your own custom cookie jar using tough-cookie, have bhttp use it, and then write your own code to store the contents of that cookie jar. This will handle all cookies that bhttp has collected, and in addition to that you will need to store the 'default settings' you've configured in your bhttp.session, if any. Those two combined should allow you to fully restore a session later.

Do make sure that you're using a 2.x.x version of tough-cookie like bhttp does; I believe that versions 3 and up are not directly compatible with bhttp right now.