Skip to content

Commit 91dadf2

Browse files
authored
http: deprecate writeHeader
PR-URL: #59060 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Tim Perry <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
1 parent eabb75c commit 91dadf2

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
returnthis;
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
functionstoreHTTPOptions(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+
constcommon=require('../common');
3+
constassert=require('assert');
4+
consthttp=require('http');
5+
6+
common.expectWarning('DeprecationWarning',
7+
'ServerResponse.prototype.writeHeader is deprecated.','DEP0063');
8+
9+
constserver=http.createServer(common.mustCall((req,res)=>{
10+
res.writeHeader(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)