Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
http: deprecate writeHeader
  • Loading branch information
bjohansebas authored Jul 14, 2025
commit d00318dc4b2681cb8b19579a0f1ce5e27379a866
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1480,12 +1480,15 @@ instead.

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/59060
description: Runtime deprecation.
- version: v8.0.0
pr-url: https://github.com/nodejs/node/pull/11355
description: Documentation-only deprecation.
-->

Type: Documentation-only
Type: Runtime

The `node:http` module `ServerResponse.prototype.writeHeader()` API is
deprecated. Please use `ServerResponse.prototype.writeHead()` instead.
Expand Down
6 changes: 4 additions & 2 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const {
} = require('internal/errors');
const {
assignFunctionName,
deprecate,
kEmptyObject,
promisify,
} = require('internal/util');
Expand Down Expand Up @@ -439,8 +440,9 @@ function writeHead(statusCode, reason, obj) {
return this;
}

// Docs-only deprecated: DEP0063
ServerResponse.prototype.writeHeader = ServerResponse.prototype.writeHead;
ServerResponse.prototype.writeHeader = deprecate(ServerResponse.prototype.writeHead,
'ServerResponse.prototype.writeHeader is deprecated.',
'DEP0063');

function storeHTTPOptions(options) {
this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-write-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

common.expectWarning('DeprecationWarning',
'ServerResponse.prototype.writeHeader is deprecated.', 'DEP0063');

const server = http.createServer(common.mustCall((req, res) => {
res.writeHeader(200, [ 'test', '2', 'test2', '2' ]);
res.end();
})).listen(0, common.mustCall(() => {
http.get({ port: server.address().port }, common.mustCall((res) => {
assert.strictEqual(res.headers.test, '2');
assert.strictEqual(res.headers.test2, '2');
res.resume().on('end', common.mustCall(() => {
server.close();
}));
}));
}));