From ab5c3e5c819ca993e0616d178bc1d282af539508 Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 13:15:06 -0700 Subject: [PATCH 1/7] auth header added --- lib/http-proxy.js | 1 + lib/http-proxy/common.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/http-proxy.js b/lib/http-proxy.js index b1ad646..8d37dd2 100644 --- a/lib/http-proxy.js +++ b/lib/http-proxy.js @@ -41,6 +41,7 @@ module.exports.createProxyServer = * prependPath: * localAddress : * changeOrigin: + * 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. * } * diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index 66e80f9..a8722f2 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -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; } From f55ffa356a259c09685c6b768a404e4b73f674ce Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 13:40:49 -0700 Subject: [PATCH 2/7] auth header added tests --- test/lib-http-proxy-common-test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 5cf36c2..3ee041f 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -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 () { From df158bfc53e35e62609d8169f3883f6dcf12b73c Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 15:11:56 -0700 Subject: [PATCH 3/7] added auth header test --- .idea/.name | 1 + .idea/encodings.xml | 4 + .idea/inspectionProfiles/Project_Default.xml | 8 + .../inspectionProfiles/profiles_settings.xml | 7 + .idea/jsLibraryMappings.xml | 6 + .idea/jsLinters/jscs.xml | 4 + .idea/jsLinters/jshint.xml | 70 +++++ .../node_http_proxy_node_modules.xml | 14 + .idea/modules.xml | 8 + .idea/node-http-proxy.iml | 9 + .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 6 + .idea/workspace.xml | 245 ++++++++++++++++++ lib/http-proxy/common.js | 2 +- ...lib-http-proxy-passes-web-incoming-test.js | 27 ++ 15 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 .idea/.name create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/jsLinters/jscs.xml create mode 100644 .idea/jsLinters/jshint.xml create mode 100644 .idea/libraries/node_http_proxy_node_modules.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/node-http-proxy.iml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..cef877d --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +node-http-proxy \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..d821048 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..65ef114 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..61cd2da --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jsLinters/jscs.xml b/.idea/jsLinters/jscs.xml new file mode 100644 index 0000000..8fc0d29 --- /dev/null +++ b/.idea/jsLinters/jscs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLinters/jshint.xml b/.idea/jsLinters/jshint.xml new file mode 100644 index 0000000..c5f5980 --- /dev/null +++ b/.idea/jsLinters/jshint.xml @@ -0,0 +1,70 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/node_http_proxy_node_modules.xml b/.idea/libraries/node_http_proxy_node_modules.xml new file mode 100644 index 0000000..2000165 --- /dev/null +++ b/.idea/libraries/node_http_proxy_node_modules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..32e963d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/node-http-proxy.iml b/.idea/node-http-proxy.iml new file mode 100644 index 0000000..99ac459 --- /dev/null +++ b/.idea/node-http-proxy.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..dea6016 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1426197133406 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index a8722f2..59ece4d 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -46,7 +46,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) { extend(outgoing.headers, options.headers); } - if(options.auth){ + if (options.auth) { outgoing.auth = options.auth; } diff --git a/test/lib-http-proxy-passes-web-incoming-test.js b/test/lib-http-proxy-passes-web-incoming-test.js index f2c6f13..f6d532d 100644 --- a/test/lib-http-proxy-passes-web-incoming-test.js +++ b/test/lib-http-proxy-passes-web-incoming-test.js @@ -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(); + }); }); \ No newline at end of file From ff1626f0719652c92895cf80f9aacc22ededadad Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 15:12:53 -0700 Subject: [PATCH 4/7] added auth header test --- .idea/.name | 1 - .idea/encodings.xml | 4 - .idea/inspectionProfiles/Project_Default.xml | 8 - .../inspectionProfiles/profiles_settings.xml | 7 - .idea/jsLibraryMappings.xml | 6 - .idea/jsLinters/jscs.xml | 4 - .idea/jsLinters/jshint.xml | 70 ----- .../node_http_proxy_node_modules.xml | 14 - .idea/modules.xml | 8 - .idea/node-http-proxy.iml | 9 - .idea/scopes/scope_settings.xml | 5 - .idea/vcs.xml | 6 - .idea/workspace.xml | 245 ------------------ 13 files changed, 387 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/jsLinters/jscs.xml delete mode 100644 .idea/jsLinters/jshint.xml delete mode 100644 .idea/libraries/node_http_proxy_node_modules.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/node-http-proxy.iml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index cef877d..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -node-http-proxy \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index d821048..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 65ef114..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 3b31283..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index 61cd2da..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/jsLinters/jscs.xml b/.idea/jsLinters/jscs.xml deleted file mode 100644 index 8fc0d29..0000000 --- a/.idea/jsLinters/jscs.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jsLinters/jshint.xml b/.idea/jsLinters/jshint.xml deleted file mode 100644 index c5f5980..0000000 --- a/.idea/jsLinters/jshint.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/libraries/node_http_proxy_node_modules.xml b/.idea/libraries/node_http_proxy_node_modules.xml deleted file mode 100644 index 2000165..0000000 --- a/.idea/libraries/node_http_proxy_node_modules.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 32e963d..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/node-http-proxy.iml b/.idea/node-http-proxy.iml deleted file mode 100644 index 99ac459..0000000 --- a/.idea/node-http-proxy.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index dea6016..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,245 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1426197133406 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 63c9262df5bd04d83432db44fce2a4d5b19a59ea Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 15:14:49 -0700 Subject: [PATCH 5/7] space instead of tabs --- test/lib-http-proxy-common-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 3ee041f..14ff875 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -17,7 +17,7 @@ describe('lib/http-proxy/common.js', function () { }, headers: {'fizz': 'bang', 'overwritten':true}, localAddress: 'local.address', - auth:'username:pass' + auth:'username:pass' }, { method : 'i', From 7298510e9170d74ff057487085bc1e898f044177 Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 15:16:17 -0700 Subject: [PATCH 6/7] space instead of tabs --- test/lib-http-proxy-common-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 14ff875..007ba39 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -17,7 +17,7 @@ describe('lib/http-proxy/common.js', function () { }, headers: {'fizz': 'bang', 'overwritten':true}, localAddress: 'local.address', - auth:'username:pass' + auth:'username:pass' }, { method : 'i', From e907d7bb2aa2825b43d9355cb1ee25bec47b15ad Mon Sep 17 00:00:00 2001 From: ashubham Date: Thu, 12 Mar 2015 15:17:26 -0700 Subject: [PATCH 7/7] end of file line space --- test/lib-http-proxy-passes-web-incoming-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib-http-proxy-passes-web-incoming-test.js b/test/lib-http-proxy-passes-web-incoming-test.js index f6d532d..cf9bf6b 100644 --- a/test/lib-http-proxy-passes-web-incoming-test.js +++ b/test/lib-http-proxy-passes-web-incoming-test.js @@ -326,4 +326,4 @@ describe('#createProxyServer.web() using own http server', function () { http.request('http://127.0.0.1:8081', function() {}).end(); }); -}); \ No newline at end of file +});