Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ tes.js
npm-debug.log
.nyc_output
coverage
.idea
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
addons:
sonarcloud:
organization: "incountry"

sudo: false
language: node_js
node_js:
- "4"
- "6"
- "8"
- "10"
script:
- npm test
after_success:
- bash <(curl -s https://codecov.io/bash)
- npm install
- sonar-scanner
matrix:
fast_finish: true
notifications:
email:
- travis@nodejitsu.com
irc: "irc.freenode.org#nodejitsu"
97 changes: 51 additions & 46 deletions lib/http-proxy/passes/web-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,64 +129,69 @@ module.exports = {

// Enable developers to modify the proxyReq before headers are sent
proxyReq.on('socket', function(socket) {
if(server) { server.emit('proxyReq', proxyReq, req, res, options); }
if(server) {
server.emit('proxyReq', proxyReq, req, res, options);
}
});

// allow outgoing socket to timeout so that we could
// show an error page at the initial request
if(options.proxyTimeout) {
proxyReq.setTimeout(options.proxyTimeout, function() {
proxyReq.abort();
});
}

// Ensure we abort proxy if request is aborted
req.on('aborted', function () {
proxyReq.abort();
});
proxyReq.on('continueWithBody', finishStream);

// handle errors in proxy and incoming request, just like for forward proxy
var proxyError = createErrorHandler(proxyReq, options.target);
req.on('error', proxyError);
proxyReq.on('error', proxyError);
function finishStream() {
// allow outgoing socket to timeout so that we could
// show an error page at the initial request
if(options.proxyTimeout) {
proxyReq.setTimeout(options.proxyTimeout, function() {
proxyReq.abort();
});
}

function createErrorHandler(proxyReq, url) {
return function proxyError(err) {
if (req.socket.destroyed && err.code === 'ECONNRESET') {
server.emit('econnreset', err, req, res, url);
return proxyReq.abort();
}
// Ensure we abort proxy if request is aborted
req.on('aborted', function () {
proxyReq.abort();
});

if (clb) {
clb(err, req, res, url);
} else {
server.emit('error', err, req, res, url);
// handle errors in proxy and incoming request, just like for forward proxy
var proxyError = createErrorHandler(proxyReq, options.target);
req.on('error', proxyError);
proxyReq.on('error', proxyError);

function createErrorHandler(proxyReq, url) {
return function proxyError(err) {
if (req.socket.destroyed && err.code === 'ECONNRESET') {
server.emit('econnreset', err, req, res, url);
return proxyReq.abort();
}

if (clb) {
clb(err, req, res, url);
} else {
server.emit('error', err, req, res, url);
}
}
}
}

(options.buffer || req).pipe(proxyReq);
(options.buffer || req).pipe(proxyReq);

proxyReq.on('response', function(proxyRes) {
if(server) { server.emit('proxyRes', proxyRes, req, res); }
proxyReq.on('response', function(proxyRes) {
if(server) { server.emit('proxyRes', proxyRes, req, res); }

if(!res.headersSent && !options.selfHandleResponse) {
for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes, options)) { break; }
if(!res.headersSent && !options.selfHandleResponse) {
for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes, options)) { break; }
}
}
}

if (!res.finished) {
// Allow us to listen when the proxy has completed
proxyRes.on('end', function () {
if (!res.finished) {
// Allow us to listen when the proxy has completed
proxyRes.on('end', function () {
if (server) server.emit('end', req, res, proxyRes);
});
// We pipe to the response unless its expected to be handled by the user
if (!options.selfHandleResponse) proxyRes.pipe(res);
} else {
if (server) server.emit('end', req, res, proxyRes);
});
// We pipe to the response unless its expected to be handled by the user
if (!options.selfHandleResponse) proxyRes.pipe(res);
} else {
if (server) server.emit('end', req, res, proxyRes);
}
});
}
});
}
}

};
23 changes: 23 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here

# Path is relative to the sonar-project.properties file. Defaults to .
sonar.sources=.
sonar.tests=test
sonar.exclusions=.git/**/*,.gitignore,.idea/**/*,venv/**/*,node_modules/**/*,test/**/*

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

#code coverage
sonar.javascript.lcov.reportPaths=coverage/lcov.info

# --- optional properties ---
## Standalone properties
sonar.projectName=node-http-proxy
sonar.organization=incountry
sonar.projectKey=incountry_node-http-proxy
sonar.projectVersion=1.0.0
#sonar.host.url=https://sonar.tools.incountry.com
#sonar.host.url=https://sonarcloud.io
#sonar.login=