Skip to content

Commit 46fe81e

Browse files
committed
Merge pull request #11 from jcrugzz/https-req-ws
[fix] add ability to proxy websockets over HTTPS
2 parents 6e77cd3 + 92de6a6 commit 46fe81e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/caronte/passes/ws.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
var http = require('http'),
2+
https = require('https'),
23
common = require('../common'),
34
passes = exports;
45

56
/*!
67
* Array of passes.
7-
*
8+
*
89
* A `pass` is just a function that is executed on `req, socket, options`
910
* so that you can easily add new checks while still keeping the base
1011
* flexible.
@@ -60,7 +61,7 @@ function XHeaders(req, socket, options) {
6061
};
6162

6263
['for', 'port', 'proto'].forEach(function(header) {
63-
req.headers['x-forwarded-' + header] =
64+
req.headers['x-forwarded-' + header] =
6465
(req.headers['x-forwarded-' + header] || '') +
6566
(req.headers['x-forwarded-' + header] ? ',' : '') +
6667
values[header]
@@ -74,10 +75,10 @@ function XHeaders(req, socket, options) {
7475
function stream(req, socket, options, head) {
7576
common.setupSocket(socket);
7677

77-
var proxyReq = http.request(
78+
var proxyReq = (options.ssl ? https : http).request(
7879
common.setupOutgoing(options.ssl || {}, options, req)
7980
);
80-
81+
8182
proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
8283
common.setupSocket(proxySocket);
8384

@@ -95,5 +96,5 @@ function stream(req, socket, options, head) {
9596

9697
] // <--
9798
.forEach(function(func) {
98-
passes[func.name] = func;
99+
passes[func.name] = func;
99100
});

0 commit comments

Comments
 (0)