Skip to content

Commit 17399e7

Browse files
committed
[fix] more jshint intendation
1 parent 0aeaba7 commit 17399e7

File tree

3 files changed

+219
-224
lines changed

3 files changed

+219
-224
lines changed

lib/caronte/passes/web-incoming.js

+112-112
Original file line numberDiff line numberDiff line change
@@ -18,132 +18,132 @@ web_o = Object.keys(web_o).map(function(pass) {
1818

1919
[ // <--
2020

21-
/**
22-
* Sets `content-length` to '0' if request is of DELETE type.
23-
*
24-
* @param {ClientRequest} Req Request object
25-
* @param {IncomingMessage} Res Response object
26-
* @param {Object} Options Config object passed to the proxy
27-
*
28-
* @api private
29-
*/
30-
31-
function deleteLength(req, res, options) {
32-
if(req.method === 'DELETE' && !req.headers['content-length']) {
33-
req.headers['content-length'] = '0';
34-
}
35-
},
36-
37-
/**
38-
* Sets timeout in request socket if it was specified in options.
39-
*
40-
* @param {ClientRequest} Req Request object
41-
* @param {IncomingMessage} Res Response object
42-
* @param {Object} Options Config object passed to the proxy
43-
*
44-
* @api private
45-
*/
46-
47-
function timeout(req, res, options) {
48-
if(options.timeout) {
49-
req.socket.setTimeout(options.timeout);
50-
}
51-
},
52-
53-
/**
54-
* Sets `x-forwarded-*` headers if specified in config.
55-
*
56-
* @param {ClientRequest} Req Request object
57-
* @param {IncomingMessage} Res Response object
58-
* @param {Object} Options Config object passed to the proxy
59-
*
60-
* @api private
61-
*/
62-
63-
function XHeaders(req, res, options) {
64-
if(!options.xfwd) return;
65-
66-
var values = {
67-
for : req.connection.remoteAddress || req.socket.remoteAddress,
68-
port : req.connection.remotePort || req.socket.remotePort,
69-
proto: req.isSpdy ? 'https' : (req.connection.pair ? 'https' : 'http')
70-
};
71-
72-
['for', 'port', 'proto'].forEach(function(header) {
73-
req.headers['x-forwarded-' + header] =
74-
(req.headers['x-forwarded-' + header] || '') +
75-
(req.headers['x-forwarded-' + header] ? ',' : '') +
76-
values[header]
77-
});
78-
},
79-
80-
/**
81-
* Does the actual proxying. If `forward` is enabled fires up
82-
* a ForwardStream, same happens for ProxyStream. The request
83-
* just dies otherwise.
84-
*
85-
* @param {ClientRequest} Req Request object
86-
* @param {IncomingMessage} Res Response object
87-
* @param {Object} Options Config object passed to the proxy
88-
*
89-
* @api private
90-
*/
21+
/**
22+
* Sets `content-length` to '0' if request is of DELETE type.
23+
*
24+
* @param {ClientRequest} Req Request object
25+
* @param {IncomingMessage} Res Response object
26+
* @param {Object} Options Config object passed to the proxy
27+
*
28+
* @api private
29+
*/
30+
31+
function deleteLength(req, res, options) {
32+
if(req.method === 'DELETE' && !req.headers['content-length']) {
33+
req.headers['content-length'] = '0';
34+
}
35+
},
36+
37+
/**
38+
* Sets timeout in request socket if it was specified in options.
39+
*
40+
* @param {ClientRequest} Req Request object
41+
* @param {IncomingMessage} Res Response object
42+
* @param {Object} Options Config object passed to the proxy
43+
*
44+
* @api private
45+
*/
46+
47+
function timeout(req, res, options) {
48+
if(options.timeout) {
49+
req.socket.setTimeout(options.timeout);
50+
}
51+
},
52+
53+
/**
54+
* Sets `x-forwarded-*` headers if specified in config.
55+
*
56+
* @param {ClientRequest} Req Request object
57+
* @param {IncomingMessage} Res Response object
58+
* @param {Object} Options Config object passed to the proxy
59+
*
60+
* @api private
61+
*/
62+
63+
function XHeaders(req, res, options) {
64+
if(!options.xfwd) return;
65+
66+
var values = {
67+
for : req.connection.remoteAddress || req.socket.remoteAddress,
68+
port : req.connection.remotePort || req.socket.remotePort,
69+
proto: req.isSpdy ? 'https' : (req.connection.pair ? 'https' : 'http')
70+
};
71+
72+
['for', 'port', 'proto'].forEach(function(header) {
73+
req.headers['x-forwarded-' + header] =
74+
(req.headers['x-forwarded-' + header] || '') +
75+
(req.headers['x-forwarded-' + header] ? ',' : '') +
76+
values[header];
77+
});
78+
},
79+
80+
/**
81+
* Does the actual proxying. If `forward` is enabled fires up
82+
* a ForwardStream, same happens for ProxyStream. The request
83+
* just dies otherwise.
84+
*
85+
* @param {ClientRequest} Req Request object
86+
* @param {IncomingMessage} Res Response object
87+
* @param {Object} Options Config object passed to the proxy
88+
*
89+
* @api private
90+
*/
91+
92+
function stream(req, res, options) {
93+
if(options.forward) {
94+
// If forward enable, so just pipe the request
95+
var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
96+
common.setupOutgoing(options.ssl || {}, options, req, 'forward')
97+
);
98+
req.pipe(forwardReq);
99+
return res.end();
100+
}
91101

92-
function stream(req, res, options) {
93-
if(options.forward) {
94-
// If forward enable, so just pipe the request
95-
var forwardReq = (options.forward.protocol === 'https:' ? https : http).request(
96-
common.setupOutgoing(options.ssl || {}, options, req, 'forward')
102+
// Request initalization
103+
var proxyReq = (options.target.protocol === 'https:' ? https : http).request(
104+
common.setupOutgoing(options.ssl || {}, options, req)
97105
);
98-
req.pipe(forwardReq);
99-
return res.end();
100-
}
101-
102-
// Request initalization
103-
var proxyReq = (options.target.protocol === 'https:' ? https : http).request(
104-
common.setupOutgoing(options.ssl || {}, options, req)
105-
);
106106

107-
// Error Handler
108-
proxyReq.on('error', function(err){
109-
var ev = 'caronte:outgoing:web:';
110-
// If no error listeners, so throw the error.
111-
if (options.ee.listeners(ev + 'error').length == 0){
107+
// Error Handler
108+
proxyReq.on('error', function(err){
109+
var ev = 'caronte:outgoing:web:';
110+
// If no error listeners, so throw the error.
111+
if (!options.ee.listeners(ev + 'error').length){
112112
throw err;
113-
}
114-
// Also emit the error events
115-
options.ee.emit(ev + 'error', err, req, res);
116-
});
113+
}
114+
// Also emit the error events
115+
options.ee.emit(ev + 'error', err, req, res);
116+
});
117117

118-
req.pipe(proxyReq);
118+
req.pipe(proxyReq);
119119

120-
proxyReq.on('response', function(proxyRes) {
121-
var ev = 'caronte:outgoing:web:';
120+
proxyReq.on('response', function(proxyRes) {
121+
var ev = 'caronte:outgoing:web:';
122122

123-
options.ee.emit(ev + 'begin', req, res);
123+
options.ee.emit(ev + 'begin', req, res);
124124

125-
// When the previous request respond, we apply the
126-
// outgoing passes to the response
127-
web_o.some(function(pass) {
128-
var evnt = ev + pass.name.toLowerCase() + ':';
125+
// When the previous request respond, we apply the
126+
// outgoing passes to the response
127+
web_o.some(function(pass) {
128+
var evnt = ev + pass.name.toLowerCase() + ':', val;
129129

130-
options.ee.emit(evnt + 'begin', req, res);
131-
// Call the pass with the proxy response
132-
// pass(ClientRequest, IncomingMessage, proxyResponse)
133-
var val = pass(req, res, proxyRes);
134-
options.ee.emit(evnt + 'end');
130+
options.ee.emit(evnt + 'begin', req, res);
131+
// Call the pass with the proxy response
132+
// pass(ClientRequest, IncomingMessage, proxyResponse)
133+
val = pass(req, res, proxyRes);
134+
options.ee.emit(evnt + 'end');
135135

136-
return val;
137-
});
136+
return val;
137+
});
138138

139-
options.ee.emit(ev + 'end');
139+
options.ee.emit(ev + 'end');
140140

141141

142-
proxyRes.pipe(res);
143-
});
142+
proxyRes.pipe(res);
143+
});
144144

145-
//proxyReq.end();
146-
}
145+
//proxyReq.end();
146+
}
147147

148148
] // <--
149149
.forEach(function(func) {

lib/caronte/passes/web-outgoing.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,9 @@ var passes = exports;
3737
*/
3838
function setConnection(req, res, proxyRes) {
3939
if (req.httpVersion === '1.0') {
40-
if (req.headers.connection) {
41-
proxyRes.headers.connection = req.headers.connection
42-
} else {
43-
proxyRes.headers.connection = 'close'
44-
}
40+
proxyRes.headers.connection = req.headers.connection || 'close';
4541
} else if (!proxyRes.headers.connection) {
46-
if (req.headers.connection) { proxyRes.headers.connection = req.headers.connection }
47-
else {
48-
proxyRes.headers.connection = 'keep-alive'
49-
}
42+
proxyRes.headers.connection = req.headers.connection || 'keep-alive';
5043
}
5144
},
5245

0 commit comments

Comments
 (0)