From 9f4cd529bc3965bb6584fc57a0ac81fa782d15f8 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Tue, 4 Apr 2017 10:54:50 +0200 Subject: [PATCH 1/2] Don't pass a body if no body was received request throws an error for HEAD requests with a body, even if the Buffer is empty --- lib/proxy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/proxy.js b/lib/proxy.js index 4b6b3e2..134ea2f 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -234,7 +234,9 @@ function bypass(req, res, params) { req.on('end', function() { params.method = req.method; - params.body = raw; + if (raw.length > 0) { + params.body = raw; + } params.headers = { 'Content-Type': req.headers['content-type'] }; From d8a60a59fc0a07e9f0e32095c3562bfde38cb1e4 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Tue, 4 Apr 2017 10:55:11 +0200 Subject: [PATCH 2/2] Add error handler a request error shouldn't crash the process --- lib/proxy.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/proxy.js b/lib/proxy.js index 134ea2f..2cce36b 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -240,7 +240,11 @@ function bypass(req, res, params) { params.headers = { 'Content-Type': req.headers['content-type'] }; - return request(params).pipe(res); + return request(params) + .on('error', function (err) { + log.error('bypass', err); + }) + .pipe(res); }); }