diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bb3a818..0f277503 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,6 @@ name: CI -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] +on: [push, pull_request] # When a PR is updated, cancel the jobs from the previous version. Merges # do not define head_ref, so use run_id to never cancel those jobs. @@ -18,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18.x, 20.x, 21.x] + node-version: [16.x, 18.x, 20.x, 22.x] steps: - uses: actions/checkout@v4 diff --git a/CHANGES.md b/CHANGES.md index 88af57b4..dce35c42 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ ### Next version +### 4.0.1 + +* Fixed proxied upstream POST request being aborted when the stream associated with the downstream request is closed on Node v16+. This will now again correctly be triggered only when the socket is closed early. + ### 4.0.0 * Removed conversion service (no longer used in TerriaJS 8+). diff --git a/lib/controllers/proxy.js b/lib/controllers/proxy.js index 93ed1ec5..11cb6097 100644 --- a/lib/controllers/proxy.js +++ b/lib/controllers/proxy.js @@ -198,8 +198,8 @@ module.exports = function(options) { // encoding : null means "body" passed to the callback will be raw bytes var proxiedRequest; - req.on('close', function() { - if (proxiedRequest) { + res.once('close', function() { + if (proxiedRequest && !res.writableEnded) { proxiedRequest.abort(); } }); diff --git a/spec/proxy.spec.js b/spec/proxy.spec.js index 10ebff99..3f398da0 100644 --- a/spec/proxy.spec.js +++ b/spec/proxy.spec.js @@ -228,7 +228,7 @@ describe('proxy', function() { request(buildApp(openProxyOptions)) [methodName]('/_2h/example.com') .set('Cache-Control', 'no-cache') - .set('x-give-response-status', '500') + .set('x-give-response-status', 500) .expect(500) .expect('cache-control', 'no-cache') .end(assert(done));