New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cookie-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cookie-client

Basic cookie-handling for outgoing requests

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

This library emulates client cookie behaviour, allowing appropriate cookie behaviour when making outgoing requests from Node.

This library is not particularly efficient for large numbers of cookies. The cookies are stored in a big list, and this entire list is searched for every request. For small numbers of cookies, or cookies on a single domain, this should not be an issue - so if you're just automatically logging into and exploring a single API, this should be fine.

If you're looking to create a full-blown multi-domain scraper or something, then raise a GitHub issue or email the author about making it more efficient.

Usage

var cookieClient = require('cookie-client');

var cookieStore = cookieClient();  // use of "new" is optional

Adding cookies from incoming response headers

cookieStore.addFromHeaders(response.headers); // full headers object
cookieStore.addFromHeaders(response.headers['set-cookie']); // just the cookie headers
request.headers['cookie'] = cookieStore.cookieStringForRequest(domain, path, isSecure);
request.headers['cookie'] = cookieStore.cookiesForRequest(domain, path, isSecure);

Public Suffix List

To prevent "super-cookies" assigning themselves domains like .com (which is dangerous), this module attempts to download a Public Suffix List (see publicsuffix.org). Any response other than a 200 will log an error to the console.

This is downloaded and stored in the module directory, so it happens once per installation.

Even if it is cached locally, it is loaded asynchronously. You can query whether the PSL has loaded yet, or request a callback:

cookieClient.pslLoaded;  // boolean flag

cookieClient,whenPslLoaded(function (error) {
	...
});

License

The code is licensed as Public Domain or MIT (your choice).

However, the file public-suffix-list.txt is taken from publicsuffix.org, and has separate licensing terms (Mozilla Public License). This package used to fetch the file from the web on first run, but that caused Node to crash if the connection was dropped by the remote server. It is therefore included in the package, but is license separately from the rest of the code.

Keywords

FAQs

Package last updated on 09 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc