From a1f9a0b376bbabb8d26f564dfb97b1bcb7a0b646 Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Mon, 28 Mar 2022 15:29:07 +0200 Subject: [PATCH 1/2] Fix example to work on current version of poem. --- Cargo.toml | 2 +- examples/poem.rs | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c657572..6e2e104 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ tokio = { version = "1.0", optional = true, features = ["macros", "rt-multi-thre warp = { version = "0.3", default-features = false, optional = true } rocket = { version = "0.5.0-rc.1", default-features = false, optional = true } axum = { version = "0.4", default-features = false, features = ["http1"], optional = true } -poem = { version = "1.0.8", default-features = false, optional = true } +poem = { version = "1.3.18", default-features = false, features = ["server"], optional = true } salvo = { version = "0.16", default-features = false, optional = true } [dev-dependencies] diff --git a/examples/poem.rs b/examples/poem.rs index 7ed2343..fa13d58 100644 --- a/examples/poem.rs +++ b/examples/poem.rs @@ -2,7 +2,7 @@ use poem::{ async_trait, http::{header, Method, StatusCode}, listener::TcpListener, - Endpoint, Request, Response, Route, Server, + Endpoint, Request, Response, Result, Route, Server, }; #[tokio::main] async fn main() -> Result<(), std::io::Error> { @@ -23,9 +23,9 @@ pub(crate) struct StaticEmbed; impl Endpoint for StaticEmbed { type Output = Response; - async fn call(&self, req: Request) -> Self::Output { + async fn call(&self, req: Request) -> Result { if req.method() != Method::GET { - return StatusCode::METHOD_NOT_ALLOWED.into(); + return Ok(StatusCode::METHOD_NOT_ALLOWED.into()); } let mut path = req.uri().path().trim_start_matches('/').trim_end_matches('/').to_string(); @@ -46,18 +46,20 @@ impl Endpoint for StaticEmbed { .map(|etag| etag.to_str().unwrap_or("000000").eq(&hash)) .unwrap_or(false) { - return StatusCode::NOT_MODIFIED.into(); + return Ok(StatusCode::NOT_MODIFIED.into()); } // otherwise, return 200 with etag hash let body: Vec = content.data.into(); let mime = mime_guess::from_path(path).first_or_octet_stream(); - Response::builder() - .header(header::CONTENT_TYPE, mime.as_ref()) - .header(header::ETAG, hash) - .body(body) + Ok( + Response::builder() + .header(header::CONTENT_TYPE, mime.as_ref()) + .header(header::ETAG, hash) + .body(body), + ) } - None => Response::builder().status(StatusCode::NOT_FOUND).finish(), + None => Ok(Response::builder().status(StatusCode::NOT_FOUND).finish()), } } } From 5574de9c39b988573e88145c6235e8ab3ff4eab7 Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Mon, 28 Mar 2022 15:29:37 +0200 Subject: [PATCH 2/2] Sort directory entries by file name to provide consistent ordering in embedded entries. --- utils/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/src/lib.rs b/utils/src/lib.rs index c88efbf..5275a3f 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -55,6 +55,7 @@ pub fn is_path_included(rel_path: &str, includes: &[&str], excludes: &[&str]) -> pub fn get_files<'patterns>(folder_path: String, includes: &'patterns [&str], excludes: &'patterns [&str]) -> impl Iterator + 'patterns { walkdir::WalkDir::new(&folder_path) .follow_links(true) + .sort_by_file_name() .into_iter() .filter_map(|e| e.ok()) .filter(|e| e.file_type().is_file())