title: Problems with digest authentication with http.client in Node.js
body: <p>I try to implement digest request when using <strong>http.get</strong> and get "<strong>Digest authentication failed</strong>" message every time :(</p>
  
  <pre><code>var hashlib = require('hashlib'),
      http = require('http'),
      url = require('url'),
      qs = require('querystring'),
      hashlib = require('hashlib');
  
  
  var username = 'user';
  var password = 'pass';
  
  var options = {
      'host' : 'username.livejournal.com',
      'path' : '/data/rss?auth=digest'
  };
  
  http.get(options, function(res) {
      res.setEncoding('utf-8');
  
      // got 401, okay
      res.on('data', function(chunk) {
  
          var authResponseParams = qs.parse(res.headers['www-authenticate'].substr(7), ', '); // cut "Digest "
  
          var ha1 = hashlib.md5(username + ':' + authResponseParams.realm + ':' + password);
          var ha2 = hashlib.md5('GET:' + options.path);
          var response = hashlib.md5(ha1 + ':' + authResponseParams.nonce + ':1::auth:' + ha2);
  
          var authRequestParams = {
              'username' : username,
              'realm' : authResponseParams.realm,
              'nonce' : authResponseParams.nonce,
              'uri' : options.path,
              'qop' : authResponseParams.qop,
              'nc' : '1',
              'cnonce' : '',
              'response' : response
          };
  
          options.headers = {
              'Authorization' : 'Digest ' + qs.stringify(authRequestParams, ',')
          };
  
          http.get(options, function(res) {
              res.setEncoding('utf-8');
  
              res.on('data', function(chunk) {
                  console.log(chunk);
              });
          });
      });
  }).on('error', function(e) {
      console.log('Got error: ' + e.message);
  });
  </code></pre>
  
  <p>What's the problem with this code?</p>