GithubHelp home page GithubHelp logo

dgmjr / file-cookie-store Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jsbizon/file-cookie-store

0.0 0.0 0.0 4.45 MB

Store cookies in Netscape file format for tough-cookie library. Attempting to update and fix but haven't had much luck yet.

License: MIT License

JavaScript 100.00%

file-cookie-store's Introduction

Build Status

Introduction

file-cookie-store - this is file store for cookie management library tough cookie. Library allow parallel access to the cookies file based on lockfile library.

Synopsis

var FileCookieStore = require('file-cookie-store');
var CookieJar = require("tough-cookie").CookieJar;

var jar = new CookieJar(new FileCookieStore("./cookie.txt", {lockfile : true}));

Installation

If you have npm installed, you can simply type:

      npm install file-cookie-store

Or you can clone this repository using the git command:

      git clone git://github.com/JSBizon/file-cookie-store.git

Usage

Class FileCookieStore has different properties:

  • force_parse - continue parse file and don't throw exception if bad line was found ( Default : false)
  • lockfile - use lockfile for access to the cookies file ( Default : true)
  • mode - mode of new created file ( Default : 438 aka 0666 in Octal)
  • http_only_extension - use http_only extension - prefix #HttpOnly_ for http only cookies. Curl, FF, etc use this kind of entries ( Default : true)
  • lockfile_retries - attempts for lock file before throw exception ( Default : 200)
  • auto_sync - in this mode cookies rewrote to the file after every change. If you set auto_sync to the false, you have to call method 'save' manually ( Default : true).

Example of using FileCookieStore without auto_sync mode:

var Q = require('q');
var FileCookieStore = require('file-cookie-store');
var TOUGH = require("tough-cookie");

var cookies_store = new FileCookieStore("./cookie.txt", {auto_sync : false});
var jar = new TOUGH.CookieJar(cookies_store);

Q.nbind(jar.setCookie, jar)(new new TOUGH.Cookie({...}), 'http://test.com/')
.then(function () {
          return Q.nbind(jar.setCookie, jar)(new TOUGH.Cookie({...}), 'http://test.com/')
}).then(function () {
          return Q.nbind(cookies_store.save, cookies_store)();//save changes to the file
});

Export cookies

For receive all cookies from the store might be used method export:

cookie_store.export(function(cookies) {
  //array cookies
});

cookie_store.export(new MemoryCookieStore(),function(memory_cookie_store) { 
  //memory_cookie_store
});

Store file format

Cookies stored in Netscape's cookie.txt file. This allow import/export cookies into/from different browsers. And use with command-line network tools: curl, wget, etc.

The layout of Netscape's cookies.txt file is such that each line contains one name-value pair. An example cookies.txt file may have an entry that looks like this:

.netscape.com TRUE / FALSE 946684799 NETSCAPE_ID 100103

Each line represents a single piece of stored information. A tab is inserted between each of the fields.

From left-to-right, here is what each field represents:

  • domain - The domain that created AND that can read the variable.
  • flag - A TRUE/FALSE value indicating if all machines within a given domain can access the variable. This value is set automatically by the browser, depending on the value you set for domain.
  • path - The path within the domain that the variable is valid for.
  • secure - A TRUE/FALSE value indicating if a secure connection with the domain is needed to access the variable.
  • expiration - The UNIX time that the variable will expire on. UNIX time is defined as the number of seconds since Jan 1, 1970 00:00:00 GMT.
  • name - The name of the variable.
  • value - The value of the variable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.