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

Commitd478a1c

Browse files
authored
Tests: Fix Karma tests on Node.js 20
Node.js 20 started throwing errors when `writeHead` is called twice ona response. This might have already been invalid before but it wasn't throwingon Node.js 18.Compute the headers object and call `writeHead` once to avoid the issue.Closesgh-5397
1 parentb507c86 commitd478a1c

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

‎test/middleware-mockserver.cjs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ const mocks = {
8080
headers["access-control-allow-origin"]="*";
8181
}
8282

83-
if(resp.set){
84-
resp.set(headers);
85-
}else{
86-
for(constkeyinheaders){
87-
resp.writeHead(200,{[key]:headers[key]});
88-
}
89-
}
83+
resp.writeHead(200,headers);
9084

9185
if(req.query.callback){
9286
resp.end(`${cleanCallback(req.query.callback)}(${JSON.stringify({
@@ -105,12 +99,14 @@ const mocks = {
10599
);
106100
},
107101
json:function(req,resp){
102+
constheaders={};
108103
if(req.query.header){
109-
resp.writeHead(200,{"content-type":"application/json"});
104+
headers["content-type"]="application/json";
110105
}
111106
if(req.query.cors){
112-
resp.writeHead(200,{"access-control-allow-origin":"*"});
107+
headers["access-control-allow-origin"]="*";
113108
}
109+
resp.writeHead(200,headers);
114110
if(req.query.array){
115111
resp.end(JSON.stringify(
116112
[{name:"John",age:21},{name:"Peter",age:25}]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp