Repository: poem-web/poem (language: rust)

Issue:
EmbeddedFilesEndpoint not working for index.html in subdirectory
I have the following two files at the same level of Cargo.toml:
```
static/index.html
static/test/index.html
```

Then I wrote the following code:
```
use poem::{endpoint::EmbeddedFilesEndpoint, listener::TcpListener, Route, Server};
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "static"]
pub struct Static;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "poem=debug");
    }
    tracing_subscriber::fmt::init();

    let app = Route::new().nest("/static", EmbeddedFilesEndpoint::<Static>::new());
    Server::new(TcpListener::bind("0.0.0.0:3000"))
        .run(app)
        .await
}

```

When I visit `http://127.0.0.1:3000/static`, the program can get `static/index.html` correctly.
When I visit `http://127.0.0.1:3000/static/test/index.html`, the program can also get `static/test/index.html` correctly.
But when I visit `http://127.0.0.1:3000/static/test` and `http://127.0.0.1:3000/static/test/`, I get 404 errors. But they should be correctly redirected to `static/test/index.html` just like `static/index.html`.
I think this is a bug.



Discussion / hints:
中文版本：
标题：EmbeddedFilesEndpoint对于子目录中的index.html不工作

我在Cargo.toml的相同层级下有如下两个文件：
```
static/index.html
static/test/index.html
```

然后我写了如下代码：
```
use poem::{endpoint::EmbeddedFilesEndpoint, listener::TcpListener, Route, Server};
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "static"]
pub struct Static;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "poem=debug");
    }
    tracing_subscriber::fmt::init();

    let app = Route::new().nest("/static", EmbeddedFilesEndpoint::<Static>::new());
    Server::new(TcpListener::bind("0.0.0.0:3000"))
        .run(app)
        .await
}
```

当我访问`http://127.0.0.1:3000/static`时，程序可以正确地获取`static/index.html`。
当我访问`http://127.0.0.1:3000/static/test/index.html`时，程序也可以正确地获取`static/test/index.html`。
但是当我访问`http://127.0.0.1:3000/static/test`以及 `http://127.0.0.1:3000/static/test/`时，均得到404错误。但它们本应该像`static/index.html`一样，被正确地重定向到`static/test/index.html`上。
我认为这是一个bug。

Fix patch:
diff --git a/poem/src/endpoint/embed.rs b/poem/src/endpoint/embed.rs
index d07aa8544f..c7165cb63d 100644
--- a/poem/src/endpoint/embed.rs
+++ b/poem/src/endpoint/embed.rs
@@ -83,16 +83,29 @@ impl<E: RustEmbed + Send + Sync> Endpoint for EmbeddedFilesEndpoint<E> {
     type Output = Response;
 
     async fn call(&self, req: Request) -> Result<Self::Output, Error> {
-        let mut path = req
-            .uri()
-            .path()
-            .trim_start_matches('/')
-            .trim_end_matches('/')
-            .to_string();
-        if path.is_empty() {
-            path = "index.html".to_string();
+        let path = req.uri().path().trim_start_matches('/');
+        let original_path = req.original_uri().path();
+        let original_end_with_slash = original_path.ends_with('/');
+
+        use header::LOCATION;
+
+        if path.is_empty() && !original_end_with_slash {
+            Ok(Response::builder()
+                .status(StatusCode::FOUND)
+                .header(LOCATION, format!("{}/", original_path))
+                .finish())
+        } else if original_end_with_slash {
+            let path = format!("{}index.html", path);
+            EmbeddedFileEndpoint::<E>::new(&path).call(req).await
+        } else if E::get(path).is_some() {
+            EmbeddedFileEndpoint::<E>::new(path).call(req).await
+        } else if E::get(&format!("{}/index.html", path)).is_some() {
+            Ok(Response::builder()
+                .status(StatusCode::FOUND)
+                .header(LOCATION, format!("{}/", original_path))
+                .finish())
+        } else {
+            EmbeddedFileEndpoint::<E>::new(path).call(req).await
         }
-        let path = path.as_ref();
-        EmbeddedFileEndpoint::<E>::new(path).call(req).await
     }
 }


Test patch: