Fixed bug in connection request digest authentication caused authentication response being sent over a new connection

This commit is contained in:
Zaid Abdulla committed 2014-03-15 16:45:58 +03:00
1 parent 13960f9f20
commit 89f153de4d
1 file changed
+6
+6
View File
@@ -8,8 +8,12 @@ auth = require './auth'
connectionRequest = (deviceId, callback) -> connectionRequest = (deviceId, callback) ->
# ensure socket is reused in case of digest authentication
agent = new http.Agent({maxSockets : 1})
conReq = (url, authString, callback) -> conReq = (url, authString, callback) ->
options = URL.parse(url) options = URL.parse(url)
options.agent = agent
if authString if authString
options.headers = {'Authorization' : authString} options.headers = {'Authorization' : authString}
@@ -18,6 +22,8 @@ connectionRequest = (deviceId, callback) ->
if res.statusCode == 401 if res.statusCode == 401
authHeader = auth.parseAuthHeader(res.headers['www-authenticate']) authHeader = auth.parseAuthHeader(res.headers['www-authenticate'])
callback(res.statusCode, authHeader) callback(res.statusCode, authHeader)
# don't need body, go ahead and emit events to free up the socket for possible reuse
res.resume()
) )
request.on('error', (err) -> request.on('error', (err) ->