Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] add an example for NLTM authentication
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var httpProxy = require('http-proxy'); | ||
var Agent = require('agentkeepalive'); | ||
|
||
var agent = new Agent({ | ||
maxSockets: 100, | ||
keepAlive: true, | ||
maxFreeSockets: 10, | ||
keepAliveMsecs:1000, | ||
timeout: 60000, | ||
keepAliveTimeout: 30000 // free socket keepalive for 30 seconds | ||
}); | ||
|
||
var proxy = httpProxy.createProxy({ target: 'http://whatever.com', agent: agent); | ||
|
||
// | ||
// Modify headers of the request before it gets sent | ||
// So that we handle the NLTM authentication request | ||
// | ||
proxy.on('proxyRes', function (proxyRes) { | ||
var key = 'www-authenticate'; | ||
proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(','); | ||
}); | ||
|
||
require('http').createServer(function (req, res) { | ||
proxy.web(req, res); | ||
}).listen(3000); |