File tree Expand file tree Collapse file tree 3 files changed +25
-24
lines changed
Expand file tree Collapse file tree 3 files changed +25
-24
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+ function setHeaders ( res , headers ) {
3+ Object . keys ( headers ) . forEach ( key => {
4+ let value = headers [ key ] ;
5+ if ( value !== null ) {
6+ res . setHeader ( key , value ) ;
7+ }
8+ } ) ;
9+ }
10+ export default function ( ) {
11+ return function ( req , res , next ) {
12+ setHeaders ( res , {
13+ "X-Content-Type-Options" : "nosniff"
14+ } ) ;
15+ next ( ) ;
16+ }
17+ }
Original file line number Diff line number Diff line change 22"use strict" ;
33import assert from "power-assert" ;
44import connect from "connect"
5+ import nosniff from "../../src/connect/nosniff" ;
56import hello from "../../src/connect/hello" ;
67import http from "http" ;
78import fetch from "node-fetch" ;
@@ -10,6 +11,7 @@ describe("hello", function () {
1011 var server ;
1112 before ( function ( done ) {
1213 var app = 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+ return fetch ( "http://localhost:3000" )
30+ . then ( res => {
31+ assert . equal ( res . headers . get ( "x-content-type-options" ) , "nosniff" ) ;
32+ } )
33+ } ) ;
2634} ) ;
You can’t perform that action at this time.
0 commit comments