mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge pull request #11 from jcrugzz/https-req-ws
[fix] add ability to proxy websockets over HTTPS
This commit is contained in:
commit
46fe81e11a
@ -1,10 +1,11 @@
|
|||||||
var http = require('http'),
|
var http = require('http'),
|
||||||
|
https = require('https'),
|
||||||
common = require('../common'),
|
common = require('../common'),
|
||||||
passes = exports;
|
passes = exports;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Array of passes.
|
* Array of passes.
|
||||||
*
|
*
|
||||||
* A `pass` is just a function that is executed on `req, socket, options`
|
* 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
|
* so that you can easily add new checks while still keeping the base
|
||||||
* flexible.
|
* flexible.
|
||||||
@ -60,7 +61,7 @@ function XHeaders(req, socket, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
['for', 'port', 'proto'].forEach(function(header) {
|
['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] || '') +
|
||||||
(req.headers['x-forwarded-' + header] ? ',' : '') +
|
(req.headers['x-forwarded-' + header] ? ',' : '') +
|
||||||
values[header]
|
values[header]
|
||||||
@ -74,10 +75,10 @@ function XHeaders(req, socket, options) {
|
|||||||
function stream(req, socket, options, head) {
|
function stream(req, socket, options, head) {
|
||||||
common.setupSocket(socket);
|
common.setupSocket(socket);
|
||||||
|
|
||||||
var proxyReq = http.request(
|
var proxyReq = (options.ssl ? https : http).request(
|
||||||
common.setupOutgoing(options.ssl || {}, options, req)
|
common.setupOutgoing(options.ssl || {}, options, req)
|
||||||
);
|
);
|
||||||
|
|
||||||
proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
|
proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
|
||||||
common.setupSocket(proxySocket);
|
common.setupSocket(proxySocket);
|
||||||
|
|
||||||
@ -95,5 +96,5 @@ function stream(req, socket, options, head) {
|
|||||||
|
|
||||||
] // <--
|
] // <--
|
||||||
.forEach(function(func) {
|
.forEach(function(func) {
|
||||||
passes[func.name] = func;
|
passes[func.name] = func;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user