Use tiny_http instead of rouille (removes 20 dependencies)

This commit is contained in:
ninjadev64 committed 2024-01-01 00:04:03 -05:00
1 parent f6c51b3968
commit 6ecad55e27
3 files changed
+25 -134

No files matched your search

+8 -127
View File
@@ -38,12 +38,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "adler32"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "ahash"
version = "0.7.7"
@@ -444,16 +438,6 @@ dependencies = [
"serde",
]
[[package]]
name = "buf_redux"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f"
dependencies = [
"memchr",
"safemem",
]
[[package]]
name = "bumpalo"
version = "3.14.0"
@@ -850,16 +834,6 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
[[package]]
name = "deflate"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f"
dependencies = [
"adler32",
"gzip-header",
]
[[package]]
name = "deranged"
version = "0.3.9"
@@ -1538,15 +1512,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "gzip-header"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95cc527b92e6029a62960ad99aa8a6660faa4555fe5f731aab13aa6a921795a2"
dependencies = [
"crc32fast",
]
[[package]]
name = "h2"
version = "0.3.21"
@@ -2201,16 +2166,6 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "miniz_oxide"
version = "0.7.1"
@@ -2232,24 +2187,6 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "multipart"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182"
dependencies = [
"buf_redux",
"httparse",
"log",
"mime",
"mime_guess",
"quick-error",
"rand 0.8.5",
"safemem",
"tempfile",
"twoway",
]
[[package]]
name = "native-tls"
version = "0.2.11"
@@ -2486,7 +2423,6 @@ dependencies = [
"lazy_static",
"log",
"os_info",
"rouille",
"serde",
"serde-inline-default",
"serde_json",
@@ -2495,8 +2431,10 @@ dependencies = [
"tauri",
"tauri-build",
"tauri-plugin-log",
"tiny_http",
"tokio",
"tokio-tungstenite",
"urlencoding",
]
[[package]]
@@ -2936,12 +2874,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quick-xml"
version = "0.30.0"
@@ -3237,30 +3169,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "rouille"
version = "3.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3716fbf57fc1084d7a706adf4e445298d123e4a44294c4e8213caf1b85fcc921"
dependencies = [
"base64 0.13.1",
"brotli",
"chrono",
"deflate",
"filetime",
"multipart",
"percent-encoding",
"rand 0.8.5",
"serde",
"serde_derive",
"serde_json",
"sha1_smol",
"threadpool",
"time",
"tiny_http",
"url",
]
[[package]]
name = "rust_decimal"
version = "1.33.1"
@@ -3589,12 +3497,6 @@ dependencies = [
"digest",
]
[[package]]
name = "sha1_smol"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]]
name = "sha2"
version = "0.10.8"
@@ -4225,15 +4127,6 @@ dependencies = [
"once_cell",
]
[[package]]
name = "threadpool"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
dependencies = [
"num_cpus",
]
[[package]]
name = "time"
version = "0.3.30"
@@ -4527,15 +4420,6 @@ dependencies = [
"utf-8",
]
[[package]]
name = "twoway"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1"
dependencies = [
"memchr",
]
[[package]]
name = "typenum"
version = "1.17.0"
@@ -4552,15 +4436,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "unicase"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.13"
@@ -4600,6 +4475,12 @@ dependencies = [
"serde",
]
[[package]]
name = "urlencoding"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]]
name = "utf-8"
version = "0.7.6"
+2 -1
View File
@@ -20,7 +20,7 @@ serde_json = "1.0"
serialport = "4.2.2"
tokio = { version = "1.34.0", features = [ "full" ] }
tokio-tungstenite = "0.20.1"
rouille = "3.6.2"
tiny_http = "0.12.0"
# Smaller utility libraries
futures-util = "0.3.29"
anyhow = "1.0.75"
@@ -30,6 +30,7 @@ serde-inline-default = "0.1.1"
serde_with = "3.4.0"
lazy_static = "1.4.0"
os_info = "3.7.0"
urlencoding = "2.1.3"
[features]
custom-protocol = [ "tauri/custom-protocol" ]
+15 -6
View File
@@ -230,8 +230,9 @@ async fn accept_connection(stream: TcpStream) {
/// Start a simple webserver to serve files of plugins that run in a browser environment.
async fn init_browser_server(prefix: path::PathBuf) {
rouille::start_server("localhost:57118", move |request| {
let url = request.url();
let server = tiny_http::Server::http("0.0.0.0:57118").unwrap();
for request in server.incoming_requests() {
let url = urlencoding::decode(request.url()).unwrap().into_owned();
// Ensure the requested path is within the OpenDeck config directory to prevent unrestricted access to the filesystem.
if path::Path::new(&url).starts_with(&prefix) {
// The Svelte frontend cannot call the connectElgatoStreamDeckSocket function on property inspector frames
@@ -242,12 +243,20 @@ async fn init_browser_server(prefix: path::PathBuf) {
let path = &url[..url.len() - 28];
let mut content = fs::read_to_string(path).unwrap_or_default();
content += "\n<script> window.addEventListener(\"message\", ({ data }) => connectElgatoStreamDeckSocket(...data)); </script>";
rouille::Response::html(content)
let response = tiny_http::Response::from_string(content);
let _ = request.respond(response.with_header(tiny_http::Header {
field: "Content-Type".parse().unwrap(),
value: "text/html".parse().unwrap()
}));
} else {
rouille::Response::html(fs::read_to_string(url).unwrap_or_default())
let response = tiny_http::Response::from_string(fs::read_to_string(url).unwrap_or_default());
let _ = request.respond(response.with_header(tiny_http::Header {
field: "Content-Type".parse().unwrap(),
value: "text/html".parse().unwrap()
}));
}
} else {
rouille::Response::empty_400()
let _ = request.respond(tiny_http::Response::empty(403));
}
});
}
}