diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/warp/examples/compression.rs | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/warp/examples/compression.rs')
-rw-r--r-- | third_party/rust/warp/examples/compression.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/third_party/rust/warp/examples/compression.rs b/third_party/rust/warp/examples/compression.rs new file mode 100644 index 0000000000..1a52c7a7d0 --- /dev/null +++ b/third_party/rust/warp/examples/compression.rs @@ -0,0 +1,34 @@ +#![deny(warnings)] + +use warp::Filter; + +#[tokio::main] +async fn main() { + let file = warp::path("todos").and(warp::fs::file("./examples/todos.rs")); + // NOTE: You could double compress something by adding a compression + // filter here, a la + // ``` + // let file = warp::path("todos") + // .and(warp::fs::file("./examples/todos.rs")) + // .with(warp::compression::brotli()); + // ``` + // This would result in a browser error, or downloading a file whose contents + // are compressed + + let dir = warp::path("ws_chat").and(warp::fs::file("./examples/websockets_chat.rs")); + + let file_and_dir = warp::get() + .and(file.or(dir)) + .with(warp::compression::gzip()); + + let examples = warp::path("ex") + .and(warp::fs::dir("./examples/")) + .with(warp::compression::deflate()); + + // GET /todos => gzip -> toods.rs + // GET /ws_chat => gzip -> ws_chat.rs + // GET /ex/... => deflate -> ./examples/... + let routes = file_and_dir.or(examples); + + warp::serve(routes).run(([127, 0, 0, 1], 3030)).await; +} |