title: How can I maintain a request session across async-waterfall calls?
body: <p>I'm trying to run a series of requests in node.js. I was advised to use <a href="https://github.com/es128/async-waterfall" rel="nofollow">async-waterfall</a>. I need to log into a remote vbulletin install and do a search for posts. </p>
  
  <pre><code>   waterfall([
      function(callback){
          var options = {
              jar: true,
  
              form: {
                  'vb_login_password': '',
                  'vb_login_username': mtfConfig.user,
                  's': '',
                  'do': 'login',
                  'vb_login_md5password': crypto.createHash('md5').update(mtfConfig.password).digest("hex"),
                  'vb_login_md5password_utf': crypto.createHash('md5').update(mtfConfig.password).digest("hex"),
                  'submit.x' :13,
                  'submit.y' :9
  
  
              },
              //formData: form,
              url: targetBaseURL+'/login.php',
              headers: {
                  'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
  
              },
              followAllRedirects:true,
              proxy: 'http://127.0.0.1:8888'
  
          }
  
          request.post(options, function(err, resp, body)
          {
              //console.log(res)
              $ = cheerio.load(body);
              var href = $('div.panel a').attr('href');
              callback(null, href, this.jar);
  
  
          });
  
      },
  
      function(href, jar, callback) {
          console.log('second callback called');
          request.get({
              jar:jar,
              url:href,
              followAllRedirects: true,
              headers: {
                  'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
  
              },
              proxy: 'http://127.0.0.1:8888'
  
          }, function(err, resp,body){
              $ = cheerio.load(body);
              console.log($('div.signup h2').text());
              callback(null, request.jar);
          });
  
      },
  
      function (jar, callback) {
          console.log('third callback - search.php')
          request.get({
              jar:jar,
              url:targetBaseURL+'/search.php',
              followAllRedirects: true,
              headers: {
                  'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
  
              },
              proxy: 'http://127.0.0.1:8888'
  
          }, function(err, resp,body){
              $ = cheerio.load(body);
              console.log(jar);
          });
  
      }
  
  ], done);
  </code></pre>
  
  <p>I've tried passing the cookie jar through from the first request but when I reach search.php, I am not logged in. How I can maintain the session cookies across requests and chained callbacks?</p>