mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge pull request #792 from ashubham/master
Adding the nodejs0.12 auth option
This commit is contained in:
commit
507f818df5
@ -41,6 +41,7 @@ module.exports.createProxyServer =
|
||||
* prependPath: <true/false, Default: true - specify whether you want to prepend the target's path to the proxy path>
|
||||
* localAddress : <Local interface string to bind for outgoing connections>
|
||||
* changeOrigin: <true/false, Default: false - changes the origin of the host header to the target URL>
|
||||
* auth : Basic authentication i.e. 'user:password' to compute an Authorization header.
|
||||
* hostRewrite: rewrites the location hostname on (301/302/307/308) redirects, Default: null.
|
||||
* }
|
||||
*
|
||||
|
||||
@ -46,6 +46,10 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
|
||||
extend(outgoing.headers, options.headers);
|
||||
}
|
||||
|
||||
if (options.auth) {
|
||||
outgoing.auth = options.auth;
|
||||
}
|
||||
|
||||
if (isSSL.test(options[forward || 'target'].protocol)) {
|
||||
outgoing.rejectUnauthorized = (typeof options.secure === "undefined") ? true : options.secure;
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ describe('lib/http-proxy/common.js', function () {
|
||||
},
|
||||
headers: {'fizz': 'bang', 'overwritten':true},
|
||||
localAddress: 'local.address',
|
||||
auth:'username:pass'
|
||||
},
|
||||
{
|
||||
method : 'i',
|
||||
@ -37,6 +38,7 @@ describe('lib/http-proxy/common.js', function () {
|
||||
expect(outgoing.headers.fizz).to.eql('bang');
|
||||
expect(outgoing.headers.overwritten).to.eql(true);
|
||||
expect(outgoing.localAddress).to.eql('local.address');
|
||||
expect(outgoing.auth).to.eql('username:pass');
|
||||
});
|
||||
|
||||
it('should not override agentless upgrade header', function () {
|
||||
|
||||
@ -299,4 +299,31 @@ describe('#createProxyServer.web() using own http server', function () {
|
||||
|
||||
http.request('http://127.0.0.1:8081', function() {}).end();
|
||||
});
|
||||
});
|
||||
|
||||
it('should proxy the request with the Authorization header set', function (done) {
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
target: 'http://127.0.0.1:8080',
|
||||
auth: 'user:pass'
|
||||
});
|
||||
|
||||
function requestHandler(req, res) {
|
||||
proxy.web(req, res);
|
||||
}
|
||||
|
||||
var proxyServer = http.createServer(requestHandler);
|
||||
|
||||
var source = http.createServer(function(req, res) {
|
||||
source.close();
|
||||
proxyServer.close();
|
||||
var auth = new Buffer(req.headers.authorization.split(' ')[1], 'base64');
|
||||
expect(req.method).to.eql('GET');
|
||||
expect(auth.toString()).to.eql('user:pass');
|
||||
done();
|
||||
});
|
||||
|
||||
proxyServer.listen('8081');
|
||||
source.listen('8080');
|
||||
|
||||
http.request('http://127.0.0.1:8081', function() {}).end();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user