Skip to content

Commit

Permalink
Merge pull request #173 from apognu/dev/reproducible-ordering
Browse files Browse the repository at this point in the history
Dev/reproducible ordering
  • Loading branch information
Peter John committed Mar 29, 2022
2 parents 74a3e07 + 5574de9 commit 9585e1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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]
Expand Down
20 changes: 11 additions & 9 deletions examples/poem.rs
Expand Up @@ -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> {
Expand All @@ -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<Self::Output> {
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();
Expand All @@ -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<u8> = 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()),
}
}
}
1 change: 1 addition & 0 deletions utils/src/lib.rs
Expand Up @@ -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<Item = FileEntry> + '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())
Expand Down

0 comments on commit 9585e1d

Please sign in to comment.