Merge pull request #11 from jcrugzz/https-req-ws

[fix] add ability to proxy websockets over HTTPS
This commit is contained in:
yawnt 2013-09-15 02:22:49 -07:00
commit 46fe81e11a

View File

@ -1,10 +1,11 @@
var http = require('http'),
https = require('https'),
common = require('../common'),
passes = exports;
/*!
* Array of passes.
*
*
* A `pass` is just a function that is executed on `req, socket, options`
* so that you can easily add new checks while still keeping the base
* flexible.
@ -60,7 +61,7 @@ function XHeaders(req, socket, options) {
};
['for', 'port', 'proto'].forEach(function(header) {
req.headers['x-forwarded-' + header] =
req.headers['x-forwarded-' + header] =
(req.headers['x-forwarded-' + header] || '') +
(req.headers['x-forwarded-' + header] ? ',' : '') +
values[header]
@ -74,10 +75,10 @@ function XHeaders(req, socket, options) {
function stream(req, socket, options, head) {
common.setupSocket(socket);
var proxyReq = http.request(
var proxyReq = (options.ssl ? https : http).request(
common.setupOutgoing(options.ssl || {}, options, req)
);
proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
common.setupSocket(proxySocket);
@ -95,5 +96,5 @@ function stream(req, socket, options, head) {
] // <--
.forEach(function(func) {
passes[func.name] = func;
passes[func.name] = func;
});