Skip to content

Commit

Permalink
Merge pull request #791 from zbynek/headers
Browse files Browse the repository at this point in the history
Make sure headers are not set twice on error
  • Loading branch information
thornjad committed May 31, 2022
2 parents 9fd0d47 + f68e454 commit 8f7fcb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/core/status-handlers.js
Expand Up @@ -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 = `${[
'<!doctype html>',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
],
"man": "./doc/http-server.1",
"engines": {
"node": ">=12"
"node": ">=12.16"
},
"contributors": [
{
Expand Down

0 comments on commit 8f7fcb0

Please sign in to comment.