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

Commit16c2d23

Browse files
committed
feat(connect): add nosniff
1 parentf1b061c commit16c2d23

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

‎src/connect/connect.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎src/connect/nosniff.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
functionsetHeaders(res,headers){
3+
Object.keys(headers).forEach(key=>{
4+
letvalue=headers[key];
5+
if(value!==null){
6+
res.setHeader(key,value);
7+
}
8+
});
9+
}
10+
exportdefaultfunction(){
11+
returnfunction(req,res,next){
12+
setHeaders(res,{
13+
"X-Content-Type-Options":"nosniff"
14+
});
15+
next();
16+
}
17+
}

‎test/connect/hello-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use strict";
33
importassertfrom"power-assert";
44
importconnectfrom"connect"
5+
importnosnifffrom"../../src/connect/nosniff";
56
importhellofrom"../../src/connect/hello";
67
importhttpfrom"http";
78
importfetchfrom"node-fetch";
@@ -10,6 +11,7 @@ describe("hello", function () {
1011
varserver;
1112
before(function(done){
1213
varapp=connect();
14+
app.use(nosniff());
1315
app.use(hello(responseText));
1416
server=http.createServer(app).listen(3000,done);
1517
});
@@ -23,4 +25,10 @@ describe("hello", function () {
2325
assert.equal(text,responseText);
2426
});
2527
});
28+
it("should return response has `X-Content-Type-Options` header",function(){
29+
returnfetch("http://localhost:3000")
30+
.then(res=>{
31+
assert.equal(res.headers.get("x-content-type-options"),"nosniff");
32+
})
33+
});
2634
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp