mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[lib] initial draft to websockets passes
This commit is contained in:
parent
4480699d3a
commit
79f7f99528
@ -1 +1,52 @@
|
||||
// ws
|
||||
/*!
|
||||
* Array of passes.
|
||||
*
|
||||
* A `pass` is just a function that is executed on `req, res, options`
|
||||
* so that you can easily add new checks while still keeping the base
|
||||
* flexible.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Websockets Passes
|
||||
*
|
||||
*/
|
||||
|
||||
var passes = exports;
|
||||
|
||||
[
|
||||
/*
|
||||
* WebSocket requests must have the `GET` method and
|
||||
* the `upgrade:websocket` header
|
||||
*/
|
||||
function checkMethodAndHeader (req, res, options) {
|
||||
if (req.method !== 'GET' || req.headers.upgrade.toLowerCase() !== 'websocket') {
|
||||
req.end();
|
||||
// Return true to prevent the next passes to be executed
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets `x-forwarded-*` headers if specified in config.
|
||||
*
|
||||
*/
|
||||
|
||||
function XHeaders(req, res, options) {
|
||||
if(!options.xfwd) return;
|
||||
|
||||
var values = {
|
||||
for : req.connection.remoteAddress || req.socket.remoteAddress,
|
||||
port : req.connection.remotePort || req.socket.remotePort,
|
||||
proto: req.connection.pair ? 'wss' : 'ws'
|
||||
};
|
||||
|
||||
['for', 'port', 'proto'].forEach(function(header) {
|
||||
req.headers['x-forwarded-' + header] =
|
||||
(req.headers['x-forwarded-' + header] || '') +
|
||||
(req.headers['x-forwarded-' + header] ? ',' : '') +
|
||||
values[header]
|
||||
});
|
||||
}
|
||||
].forEach(function(func) {
|
||||
passes[func.name] = func;
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user