From 7222fce684c0c076be7bac4703f341735d48d8fa Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sat, 2 May 2020 16:45:42 +0200 Subject: [PATCH] Extend supported Node.js from <=9 to <=14 --- .travis.yml | 5 +++++ lib/cors-anywhere.js | 5 +++++ test/test.js | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f4d6c76..2d0ea40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,11 @@ node_js: - 7 - 8 - 9 + - 11 + - 12 + - 13 + - 13 + - 14 script: - npm run lint - npm run test diff --git a/lib/cors-anywhere.js b/lib/cors-anywhere.js index bedfc47..b92eb4e 100644 --- a/lib/cors-anywhere.js +++ b/lib/cors-anywhere.js @@ -413,6 +413,11 @@ exports.createServer = function createServer(options) { // This could happen when a protocol error occurs when an error occurs // after the headers have been received (and forwarded). Do not write // the headers because it would generate an error. + // Prior to Node 13.x, the stream would have ended. + // As of Node 13.x, we must explicitly close it. + if (res.writableEnded === false) { + res.end(); + } return; } diff --git a/test/test.js b/test/test.js index 66b2008..2951cc0 100644 --- a/test/test.js +++ b/test/test.js @@ -385,10 +385,15 @@ describe('Proxy errors', function() { }); it('Content-Length mismatch', function(done) { + var errorMessage = 'Error: Parse Error: Invalid character in Content-Length'; + // <13.0.0: https://github.com/nodejs/node/commit/ba565a37349e81c9d2402b0c8ef05ab39dca8968 + if (parseInt(process.versions.node, 10) < 13) { + errorMessage = 'Error: Parse Error'; + } request(cors_anywhere) .get('/' + bad_http_server_url) .expect('Access-Control-Allow-Origin', '*') - .expect(404, 'Not found because of proxy error: Error: Parse Error', done); + .expect(404, 'Not found because of proxy error: ' + errorMessage, done); }); it('Invalid HTTP status code', function(done) {