Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc03354d

Browse files
test: test case for multiple res.writeHead and res.getHeader
PR-URL:#45508Fixes:#36721Reviewed-By: Robert Nagy <ronagy@icloud.com>Reviewed-By: Paolo Insogna <paolo@cowtech.it>Reviewed-By: Luigi Pinca <luigipinca@gmail.com>Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parentbe9cd3e commitc03354d

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

‎lib/_http_server.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ ServerResponse.prototype._implicitHeader = function _implicitHeader() {
331331

332332
ServerResponse.prototype.writeHead=writeHead;
333333
functionwriteHead(statusCode,reason,obj){
334+
335+
if(this._header){
336+
thrownewERR_HTTP_HEADERS_SENT('write');
337+
}
338+
334339
constoriginalStatusCode=statusCode;
335340

336341
statusCode|=0;

‎test/parallel/test-domain-multi.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ const server = http.createServer((req, res) => {
4646

4747
b.on('error',common.mustCall((er)=>{
4848
if(res){
49-
res.writeHead(500);
50-
res.end('An error occurred');
49+
// Introduce an error on the client by writing unexpected data.
50+
// The client is now expecting a chunk header so any letter will have the parser throw an error.
51+
res.socket.write('H');
5152
}
5253
// res.writeHead(500), res.destroy, etc.
5354
server.close();

‎test/parallel/test-http-write-head.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const s = http.createServer(common.mustCall((req, res) => {
5858
},{
5959
code:'ERR_HTTP_HEADERS_SENT',
6060
name:'Error',
61-
message:'Cannot render headers after they are sent to the client'
6261
});
6362

6463
res.end();
@@ -76,3 +75,24 @@ function runTest() {
7675
response.resume();
7776
}));
7877
}
78+
79+
{
80+
constserver=http.createServer(common.mustCall((req,res)=>{
81+
res.writeHead(200,['test','1']);
82+
assert.throws(()=>res.writeHead(200,['test2','2']),{
83+
code:'ERR_HTTP_HEADERS_SENT',
84+
name:'Error',
85+
});
86+
res.end();
87+
}));
88+
89+
server.listen(0,common.mustCall(()=>{
90+
http.get({port:server.address().port},(res)=>{
91+
assert.strictEqual(res.headers.test,'1');
92+
assert.strictEqual('test2'inres.headers,false);
93+
res.resume().on('end',common.mustCall(()=>{
94+
server.close();
95+
}));
96+
});
97+
}));
98+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp