mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[refactor] clean up
This commit is contained in:
parent
27d23592d1
commit
5b570e1215
@ -155,6 +155,18 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
req.pipe(new ForwardStream(options.forward));
|
||||
}
|
||||
|
||||
//
|
||||
// Handle 'error' events from the `req` (e.g. `Parse Error`).
|
||||
//
|
||||
req.on('error', proxyError);
|
||||
|
||||
//Aborts pReq if client aborts the connection.
|
||||
req.on('close', function () {
|
||||
if (!errState) {
|
||||
pReq.abort();
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// #### function proxyError (err)
|
||||
// #### @err {Error} Error contacting the proxy target
|
||||
@ -179,27 +191,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
// This NODE_ENV=production behavior is mimics Express and
|
||||
// Connect.
|
||||
//
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
res.write('Internal Server Error');
|
||||
}
|
||||
else {
|
||||
res.write('An error has occurred: ' + JSON.stringify(err));
|
||||
}
|
||||
|
||||
res.write(process.env.NODE_ENV === 'production' ?
|
||||
'Internal Server Error' :
|
||||
'An error has occurred: ' + JSON.stringify(err) ;
|
||||
);
|
||||
}
|
||||
|
||||
try { res.end() }
|
||||
catch (ex) { console.error('res.end error: %s', ex.message) }
|
||||
}
|
||||
|
||||
//
|
||||
// Handle 'error' events from the `req` (e.g. `Parse Error`).
|
||||
//
|
||||
req.on('error', proxyError);
|
||||
|
||||
//Aborts pReq if client aborts the connection.
|
||||
req.on('close', function () {
|
||||
if (!errState) {
|
||||
pReq.abort();
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -86,18 +86,7 @@ ProxyStream.prototype.start = function (req) {
|
||||
//
|
||||
// Process the `pReq` `pRes` when it's received.
|
||||
//
|
||||
if (req.httpVersion === '1.0') {
|
||||
if (req.headers.connection) {
|
||||
pRes.headers.connection = req.headers.connection
|
||||
} else {
|
||||
pRes.headers.connection = 'close'
|
||||
}
|
||||
} else if (!pRes.headers.connection) {
|
||||
if (req.headers.connection) { pRes.headers.connection = req.headers.connection }
|
||||
else {
|
||||
pRes.headers.connection = 'keep-alive'
|
||||
}
|
||||
}
|
||||
pRes.headers.connection = req.headers.connection || req.httpVersion === '1.0' ? 'close' : 'keep-alive';
|
||||
|
||||
// Remove `Transfer-Encoding` header if client's protocol is HTTP/1.0
|
||||
// or if this is a DELETE request with no content-length header.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user