mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Made it not to crash with omited Host http header (#1050)
This commit is contained in:
parent
cbd5777060
commit
b781af641a
@ -79,7 +79,7 @@ web_o = Object.keys(web_o).map(function(pass) {
|
||||
values[header];
|
||||
});
|
||||
|
||||
req.headers['x-forwarded-host'] = req.headers['host'];
|
||||
req.headers['x-forwarded-host'] = req.headers['host'] || '';
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
var httpProxy = require('../lib/http-proxy'),
|
||||
expect = require('expect.js'),
|
||||
http = require('http'),
|
||||
ws = require('ws')
|
||||
net = require('net'),
|
||||
ws = require('ws'),
|
||||
io = require('socket.io'),
|
||||
SSE = require('sse'),
|
||||
ioClient = require('socket.io-client');
|
||||
@ -17,7 +18,6 @@ Object.defineProperty(gen, 'port', {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
describe('lib/http-proxy.js', function() {
|
||||
describe('#createProxyServer', function() {
|
||||
it.skip('should throw without options', function() {
|
||||
@ -223,11 +223,54 @@ describe('lib/http-proxy.js', function() {
|
||||
});
|
||||
|
||||
testReq.end();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createProxyServer with xfwd option', function () {
|
||||
it('should not throw on empty http host header', function (done) {
|
||||
var ports = { source: gen.port, proxy: gen.port };
|
||||
var proxy = httpProxy.createProxyServer({
|
||||
forward: 'http://127.0.0.1:' + ports.source,
|
||||
xfwd: true
|
||||
}).listen(ports.proxy);
|
||||
|
||||
var source = http.createServer(function(req, res) {
|
||||
expect(req.method).to.eql('GET');
|
||||
expect(req.headers.host.split(':')[1]).to.eql(ports.source);
|
||||
source.close();
|
||||
proxy.close();
|
||||
done();
|
||||
});
|
||||
|
||||
source.listen(ports.source);
|
||||
|
||||
var socket = net.connect({port: ports.proxy}, function()
|
||||
{
|
||||
socket.write('GET / HTTP/1.0\r\n\r\n');
|
||||
});
|
||||
|
||||
// handle errors
|
||||
socket.on('error', function()
|
||||
{
|
||||
expect.fail('Unexpected socket error');
|
||||
});
|
||||
|
||||
socket.on('data', function(data)
|
||||
{
|
||||
socket.end();
|
||||
});
|
||||
|
||||
socket.on('end', function()
|
||||
{
|
||||
expect('Socket to finish').to.be.ok();
|
||||
});
|
||||
|
||||
// http.request('http://127.0.0.1:' + ports.proxy, function() {}).end();
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
// describe('#createProxyServer using the web-incoming passes', function () {
|
||||
// it('should emit events correclty', function(done) {
|
||||
// it('should emit events correctly', function(done) {
|
||||
// var proxy = httpProxy.createProxyServer({
|
||||
// target: 'http://127.0.0.1:8080'
|
||||
// }),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user