Skip to content

Commit 04a2638

Browse files
authored
http: deprecate writeHeader
1 parent 4dafa77 commit 04a2638

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,12 +1480,15 @@ instead.
14801480

14811481
<!-- YAML
14821482
changes:
1483+
- version: REPLACEME
1484+
pr-url: https://github.com/nodejs/node/pull/59060
1485+
description: Runtime deprecation.
14831486
- version: v8.0.0
14841487
pr-url: https://github.com/nodejs/node/pull/11355
14851488
description: Documentation-only deprecation.
14861489
-->
14871490

1488-
Type: Documentation-only
1491+
Type: Runtime
14891492

14901493
The `node:http` module `ServerResponse.prototype.writeHeader()` API is
14911494
deprecated. Please use `ServerResponse.prototype.writeHead()` instead.

lib/_http_server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const {
8181
} = require('internal/errors');
8282
const {
8383
assignFunctionName,
84+
deprecate,
8485
kEmptyObject,
8586
promisify,
8687
} = require('internal/util');
@@ -439,8 +440,9 @@ function writeHead(statusCode, reason, obj) {
439440
return this;
440441
}
441442

442-
// Docs-only deprecated: DEP0063
443-
ServerResponse.prototype.writeHeader = ServerResponse.prototype.writeHead;
443+
ServerResponse.prototype.writeHeader = deprecate(ServerResponse.prototype.writeHead,
444+
'ServerResponse.prototype.writeHeader is deprecated.',
445+
'DEP0063');
444446

445447
function storeHTTPOptions(options) {
446448
this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;

test/parallel/test-write-header.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
6+
common.expectWarning('DeprecationWarning',
7+
'ServerResponse.prototype.writeHeader is deprecated.', 'DEP0063');
8+
9+
const server = http.createServer(common.mustCall((req, res) => {
10+
res.writeHead(200, [ 'test', '2', 'test2', '2' ]);
11+
res.end();
12+
})).listen(0, common.mustCall(() => {
13+
http.get({ port: server.address().port }, common.mustCall((res) => {
14+
assert.strictEqual(res.headers.test, '2');
15+
assert.strictEqual(res.headers.test2, '2');
16+
res.resume().on('end', common.mustCall(() => {
17+
server.close();
18+
}));
19+
}));
20+
}));

0 commit comments

Comments
 (0)