"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/request/lib/cookies.js" (8 Mar 2017, 969 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 
    3 var tough = require('tough-cookie')
    4 
    5 var Cookie = tough.Cookie
    6   , CookieJar = tough.CookieJar
    7 
    8 
    9 exports.parse = function(str) {
   10   if (str && str.uri) {
   11     str = str.uri
   12   }
   13   if (typeof str !== 'string') {
   14     throw new Error('The cookie function only accepts STRING as param')
   15   }
   16   return Cookie.parse(str, {loose: true})
   17 }
   18 
   19 // Adapt the sometimes-Async api of tough.CookieJar to our requirements
   20 function RequestJar(store) {
   21   var self = this
   22   self._jar = new CookieJar(store, {looseMode: true})
   23 }
   24 RequestJar.prototype.setCookie = function(cookieOrStr, uri, options) {
   25   var self = this
   26   return self._jar.setCookieSync(cookieOrStr, uri, options || {})
   27 }
   28 RequestJar.prototype.getCookieString = function(uri) {
   29   var self = this
   30   return self._jar.getCookieStringSync(uri)
   31 }
   32 RequestJar.prototype.getCookies = function(uri) {
   33   var self = this
   34   return self._jar.getCookiesSync(uri)
   35 }
   36 
   37 exports.jar = function(store) {
   38   return new RequestJar(store)
   39 }