Skip to content

Commit 71a06aa

Browse files
committed
[test] add tests for the changeOrigin cases in properly setting the host header
1 parent 501e8c2 commit 71a06aa

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/lib-http-proxy-common-test.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe('lib/http-proxy/common.js', function () {
216216
//
217217
// This is the proper failing test case for the common.join problem
218218
//
219-
it('should correctly format the a toProxy URL', function () {
219+
it('should correctly format the toProxy URL', function () {
220220
var outgoing = {};
221221
var google = 'https://google.com'
222222
common.setupOutgoing(outgoing, {
@@ -225,7 +225,33 @@ describe('lib/http-proxy/common.js', function () {
225225
}, { url: google });
226226

227227
expect(outgoing.path).to.eql('/' + google);
228-
})
228+
});
229+
230+
describe('when using changeOrigin', function () {
231+
it('should correctly set the port to the host when it is a non-standard port using url.parse', function () {
232+
var outgoing = {};
233+
var myEndpoint = 'https://myCouch.com:6984';
234+
common.setupOutgoing(outgoing, {
235+
target: url.parse(myEndpoint),
236+
changeOrigin: true
237+
}, { url: '/' });
238+
239+
expect(outgoing.headers.host).to.eql('mycouch.com:6984');
240+
});
241+
it('should correctly set the port to the host when it is a non-standard port when setting host and port manually (which ignores port)', function () {
242+
var outgoing = {};
243+
common.setupOutgoing(outgoing, {
244+
target: {
245+
protocol: 'https:',
246+
host: 'mycouch.com',
247+
port: 6984
248+
},
249+
changeOrigin: true
250+
}, { url: '/' });
251+
expect(outgoing.headers.host).to.eql('mycouch.com:6984');
252+
})
253+
});
254+
229255
});
230256

231257
describe('#setupSocket', function () {

0 commit comments

Comments
 (0)