File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -133,8 +133,6 @@ function listen(port) {
133133 password : argv . password || process . env . NODE_HTTP_SERVER_PASSWORD
134134 } ;
135135
136- options . headers = { } ;
137-
138136 if ( argv . cors && argv . coi ) {
139137 logger . info ( colors . red ( 'Error: conflicting arguments: --cors and --coi' ) ) ;
140138 process . exit ( 1 ) ;
@@ -147,8 +145,7 @@ function listen(port) {
147145 }
148146 }
149147 else if ( argv . coi ) {
150- options . headers [ 'Cross-Origin-Embedder-Policy' ] = 'require-corp' ;
151- options . headers [ 'Cross-Origin-Opener-Policy' ] = 'same-origin' ;
148+ options . coi = true ;
152149 }
153150
154151 if ( ssl ) {
Original file line number Diff line number Diff line change @@ -134,6 +134,11 @@ function HttpServer(options) {
134134 } : null ) ) ;
135135 }
136136
137+ if ( options . coi ) {
138+ this . headers [ 'Cross-Origin-Embedder-Policy' ] = 'require-corp' ;
139+ this . headers [ 'Cross-Origin-Opener-Policy' ] = 'same-origin' ;
140+ }
141+
137142 if ( options . robots ) {
138143 before . push ( function ( req , res ) {
139144 if ( req . url === '/robots.txt' ) {
Original file line number Diff line number Diff line change @@ -167,6 +167,26 @@ vows.describe('http-server').addBatch({
167167 server . close ( ) ;
168168 }
169169 } ,
170+ 'When cross origin isolation is enabled,\n' : {
171+ topic : function ( ) {
172+ var server = httpServer . createServer ( {
173+ root : root ,
174+ coi : true
175+ } ) ;
176+
177+ server . listen ( 8080 ) ;
178+ this . callback ( null , server ) ;
179+ } ,
180+ 'and a page is requested' : {
181+ topic : function ( ) {
182+ request ( 'http://127.0.0.1:8080/' , this . callback ) ;
183+ } ,
184+ 'response should have cross origin isolation headers set' : function ( err , res ) {
185+ assert . equal ( res . headers [ 'Cross-Origin-Embedder-Policy' ] , 'require-corp' ) ;
186+ assert . equal ( res . headers [ 'Cross-Origin-Opener-Policy' ] , 'same-origin' ) ;
187+ }
188+ }
189+ } ,
170190 'When gzip and brotli compression is enabled and a compressed file is available' : {
171191 topic : function ( ) {
172192 var server = httpServer . createServer ( {
You can’t perform that action at this time.
0 commit comments