Skip to content
Snippets Groups Projects
Unverified Commit bd2837da authored by LinFeng's avatar LinFeng Committed by GitHub
Browse files

Merge pull request #70 from s-d-m/add_coop_coep_options

feat: add headers useful to allow use of threads with webassembly
parents 82f01f42 aede9afc
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,8 @@ USAGE: ...@@ -11,6 +11,8 @@ USAGE:
simple-http-server [FLAGS] [OPTIONS] [--] [root] simple-http-server [FLAGS] [OPTIONS] [--] [root]
FLAGS: FLAGS:
--coep Add "Cross-Origin-Embedder-Policy" HTTP header and set it to "require-corp"
--coop Add "Cross-Origin-Opener-Policy" HTTP header and set it to "same-origin"
--cors Enable CORS via the "Access-Control-Allow-Origin" header --cors Enable CORS via the "Access-Control-Allow-Origin" header
-h, --help Prints help information -h, --help Prints help information
-i, --index Enable automatic render index page [index.html, index.htm] -i, --index Enable automatic render index page [index.html, index.htm]
......
...@@ -102,6 +102,12 @@ fn main() { ...@@ -102,6 +102,12 @@ fn main() {
.arg(clap::Arg::with_name("cors") .arg(clap::Arg::with_name("cors")
.long("cors") .long("cors")
.help("Enable CORS via the \"Access-Control-Allow-Origin\" header")) .help("Enable CORS via the \"Access-Control-Allow-Origin\" header"))
.arg(clap::Arg::with_name("coop")
.long("coop")
.help("Add \"Cross-Origin-Opener-Policy\" HTTP header and set it to \"same-origin\""))
.arg(clap::Arg::with_name("coep")
.long("coep")
.help("Add \"Cross-Origin-Embedder-Policy\" HTTP header and set it to \"require-corp\""))
.arg(clap::Arg::with_name("certpass"). .arg(clap::Arg::with_name("certpass").
long("certpass") long("certpass")
.takes_value(true) .takes_value(true)
...@@ -222,6 +228,8 @@ fn main() { ...@@ -222,6 +228,8 @@ fn main() {
let cert = matches.value_of("cert"); let cert = matches.value_of("cert");
let certpass = matches.value_of("certpass"); let certpass = matches.value_of("certpass");
let cors = matches.is_present("cors"); let cors = matches.is_present("cors");
let coop = matches.is_present("coop");
let coep = matches.is_present("coep");
let ip = matches.value_of("ip").unwrap(); let ip = matches.value_of("ip").unwrap();
let port = matches.value_of("port").unwrap().parse::<u16>().unwrap(); let port = matches.value_of("port").unwrap().parse::<u16>().unwrap();
let upload_size_limit = matches let upload_size_limit = matches
...@@ -277,7 +285,7 @@ fn main() { ...@@ -277,7 +285,7 @@ fn main() {
if !silent { if !silent {
printer printer
.println_out( .println_out(
r#" Index: {}, Cache: {}, Cors: {}, Range: {}, Sort: {}, Threads: {} r#" Index: {}, Cache: {}, Cors: {}, Coop: {}, Coep: {}, Range: {}, Sort: {}, Threads: {}
Upload: {}, CSRF Token: {} Upload: {}, CSRF Token: {}
Auth: {}, Compression: {} Auth: {}, Compression: {}
https: {}, Cert: {}, Cert-Password: {} https: {}, Cert: {}, Cert-Password: {}
...@@ -289,6 +297,8 @@ fn main() { ...@@ -289,6 +297,8 @@ fn main() {
enable_string(index), enable_string(index),
enable_string(cache), enable_string(cache),
enable_string(cors), enable_string(cors),
enable_string(coop),
enable_string(coep),
enable_string(range), enable_string(range),
enable_string(sort), enable_string(sort),
threads.to_string(), threads.to_string(),
...@@ -331,6 +341,8 @@ fn main() { ...@@ -331,6 +341,8 @@ fn main() {
upload, upload,
cache, cache,
range, range,
coop,
coep,
redirect_to, redirect_to,
sort, sort,
compress: compress compress: compress
...@@ -411,6 +423,8 @@ struct MainHandler { ...@@ -411,6 +423,8 @@ struct MainHandler {
upload: Option<Upload>, upload: Option<Upload>,
cache: bool, cache: bool,
range: bool, range: bool,
coop: bool,
coep: bool,
redirect_to: Option<iron::Url>, redirect_to: Option<iron::Url>,
sort: bool, sort: bool,
compress: Option<Vec<String>>, compress: Option<Vec<String>>,
...@@ -896,7 +910,18 @@ impl MainHandler { ...@@ -896,7 +910,18 @@ impl MainHandler {
let mime = mime_types::from_path(path).first_or_octet_stream(); let mime = mime_types::from_path(path).first_or_octet_stream();
resp.headers resp.headers
.set_raw("content-type", vec![mime.to_string().into_bytes()]); .set_raw("content-type", vec![mime.to_string().into_bytes()]);
if self.coop {
resp.headers.set_raw(
"Cross-Origin-Opener-Policy",
vec!["same-origin".to_string().into_bytes()],
);
}
if self.coep {
resp.headers.set_raw(
"Cross-Origin-Embedder-Policy",
vec!["require-corp".to_string().into_bytes()],
);
}
if self.range { if self.range {
let mut range = req.headers.get::<Range>(); let mut range = req.headers.get::<Range>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment