Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure headers are not set twice on error #791

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/core/status-handlers.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
],
"man": "./doc/http-server.1",
"engines": {
"node": ">=12"
"node": ">=12.16"
},
"contributors": [
{
Expand Down