mikeal/request — pull request #635 by randymized (2013-08-20 19:48:58+00:00)
Title: Add ability to receive a 401 challenge once and then authorize any number of requests based upon that challenge

As currently implemented, every request sent by request for a resource protected by digest protected by HTTP digest authentication would require a new 401 response. This pull request adds a digestAuth option, which works much the same way as the jar option allows maintaining cookies between requests, except that the object provided to the digestAuth option would maintain a 401 challenge from one request to the next.

The digestAuth option should reference an object that implements an interface consisting of the following two functions:
1. get_challenge(response), which will be invoked whenever a 401 response is received. It should parse the challenge posed by the WWW-Authenticate header and save that challenge for later authorization requests.
2. authentication_string(method,path), which returns either a false value or a string to be placed in an Authorization header. If no challenge has been received, it will return a false value. This function may be called multiple times in order to authorize multiple requests.

A suitable digestAuth object is produced by the [www-authenticate module](https://github.com/randymized/www-authenticate), such as in the the following usage example:
```javascript
var request = require('request');
var www_authenticate = require('www-authenticate');
var digestAuth= www_authenticate.authenticator(username,password);
request({method:'GET',uri:'/something',digestAuth:digestAuth});
request({method:'GET',uri:'/something/else',digestAuth:digestAuth});
```