@@ -102,6 +102,12 @@ fn main() {
102102 . arg ( clap:: Arg :: with_name ( "cors" )
103103 . long ( "cors" )
104104 . help ( "Enable CORS via the \" Access-Control-Allow-Origin\" header" ) )
105+ . arg ( clap:: Arg :: with_name ( "coop" )
106+ . long ( "coop" )
107+ . help ( "Add \" Cross-Origin-Opener-Policy\" HTTP header and set it to \" same-origin\" " ) )
108+ . arg ( clap:: Arg :: with_name ( "coep" )
109+ . long ( "coep" )
110+ . help ( "Add \" Cross-Origin-Embedder-Policy\" HTTP header and set it to \" require-corp\" " ) )
105111 . arg ( clap:: Arg :: with_name ( "certpass" ) .
106112 long ( "certpass" )
107113 . takes_value ( true )
@@ -222,6 +228,8 @@ fn main() {
222228 let cert = matches. value_of ( "cert" ) ;
223229 let certpass = matches. value_of ( "certpass" ) ;
224230 let cors = matches. is_present ( "cors" ) ;
231+ let coop = matches. is_present ( "coop" ) ;
232+ let coep = matches. is_present ( "coep" ) ;
225233 let ip = matches. value_of ( "ip" ) . unwrap ( ) ;
226234 let port = matches. value_of ( "port" ) . unwrap ( ) . parse :: < u16 > ( ) . unwrap ( ) ;
227235 let upload_size_limit = matches
@@ -277,7 +285,7 @@ fn main() {
277285 if !silent {
278286 printer
279287 . println_out (
280- r#" Index: {}, Cache: {}, Cors: {}, Range: {}, Sort: {}, Threads: {}
288+ r#" Index: {}, Cache: {}, Cors: {}, Coop: {}, Coep: {}, Range: {}, Sort: {}, Threads: {}
281289 Upload: {}, CSRF Token: {}
282290 Auth: {}, Compression: {}
283291 https: {}, Cert: {}, Cert-Password: {}
@@ -289,6 +297,8 @@ fn main() {
289297 enable_string( index) ,
290298 enable_string( cache) ,
291299 enable_string( cors) ,
300+ enable_string( coop) ,
301+ enable_string( coep) ,
292302 enable_string( range) ,
293303 enable_string( sort) ,
294304 threads. to_string( ) ,
@@ -331,6 +341,8 @@ fn main() {
331341 upload,
332342 cache,
333343 range,
344+ coop,
345+ coep,
334346 redirect_to,
335347 sort,
336348 compress : compress
@@ -411,6 +423,8 @@ struct MainHandler {
411423 upload : Option < Upload > ,
412424 cache : bool ,
413425 range : bool ,
426+ coop : bool ,
427+ coep : bool ,
414428 redirect_to : Option < iron:: Url > ,
415429 sort : bool ,
416430 compress : Option < Vec < String > > ,
@@ -896,7 +910,18 @@ impl MainHandler {
896910 let mime = mime_types:: from_path ( path) . first_or_octet_stream ( ) ;
897911 resp. headers
898912 . set_raw ( "content-type" , vec ! [ mime. to_string( ) . into_bytes( ) ] ) ;
899-
913+ if self . coop {
914+ resp. headers . set_raw (
915+ "Cross-Origin-Opener-Policy" ,
916+ vec ! [ "same-origin" . to_string( ) . into_bytes( ) ] ,
917+ ) ;
918+ }
919+ if self . coep {
920+ resp. headers . set_raw (
921+ "Cross-Origin-Embedder-Policy" ,
922+ vec ! [ "require-corp" . to_string( ) . into_bytes( ) ] ,
923+ ) ;
924+ }
900925 if self . range {
901926 let mut range = req. headers . get :: < Range > ( ) ;
902927
0 commit comments