From f68e454ac9f0b38c4b8f8a07f3162fbaaa996eaa Mon Sep 17 00:00:00 2001 From: Zbynek Konecny Date: Sun, 23 Jan 2022 23:20:36 +0100 Subject: [PATCH] Make sure headers are not set twice on error --- lib/core/status-handlers.js | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/core/status-handlers.js b/lib/core/status-handlers.js index 265b399e5..78c1772a9 100644 --- a/lib/core/status-handlers.js +++ b/lib/core/status-handlers.js @@ -54,7 +54,11 @@ exports['416'] = (res, next) => { // flagrant error exports['500'] = (res, next, opts) => { res.statusCode = 500; - res.setHeader('content-type', 'text/html'); + try { + res.setHeader('content-type', 'text/html'); + } catch (e) { + // errors may have triggered headers being sent already, make sure we don't hide the underlying error + } const error = String(opts.error.stack || opts.error || 'No specified error'); const html = `${[ '', diff --git a/package.json b/package.json index 669b139bc..3a95dc81f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ ], "man": "./doc/http-server.1", "engines": { - "node": ">=12" + "node": ">=12.16" }, "contributors": [ {