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:
simple-http-server [FLAGS] [OPTIONS] [--] [root]
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
-h, --help Prints help information
-i, --index Enable automatic render index page [index.html, index.htm]
......
......@@ -102,6 +102,12 @@ fn main() {
.arg(clap::Arg::with_name("cors")
.long("cors")
.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").
long("certpass")
.takes_value(true)
......@@ -222,6 +228,8 @@ fn main() {
let cert = matches.value_of("cert");
let certpass = matches.value_of("certpass");
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 port = matches.value_of("port").unwrap().parse::<u16>().unwrap();
let upload_size_limit = matches
......@@ -277,7 +285,7 @@ fn main() {
if !silent {
printer
.println_out(
r#" Index: {}, Cache: {}, Cors: {}, Range: {}, Sort: {}, Threads: {}
r#" Index: {}, Cache: {}, Cors: {}, Coop: {}, Coep: {}, Range: {}, Sort: {}, Threads: {}
Upload: {}, CSRF Token: {}
Auth: {}, Compression: {}
https: {}, Cert: {}, Cert-Password: {}
......@@ -289,6 +297,8 @@ fn main() {
enable_string(index),
enable_string(cache),
enable_string(cors),
enable_string(coop),
enable_string(coep),
enable_string(range),
enable_string(sort),
threads.to_string(),
......@@ -331,6 +341,8 @@ fn main() {
upload,
cache,
range,
coop,
coep,
redirect_to,
sort,
compress: compress
......@@ -411,6 +423,8 @@ struct MainHandler {
upload: Option<Upload>,
cache: bool,
range: bool,
coop: bool,
coep: bool,
redirect_to: Option<iron::Url>,
sort: bool,
compress: Option<Vec<String>>,
......@@ -896,7 +910,18 @@ impl MainHandler {
let mime = mime_types::from_path(path).first_or_octet_stream();
resp.headers
.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 {
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