Skip to content

Trailing Slash #562

Answered by ir1keren
ir1keren asked this question in Q&A
Apr 15, 2025 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Finally, after banging my heads several times, I can get it working:

use ntex::http::uri::{PathAndQuery, Uri};
use ntex::util::Bytes;
use ntex::{forward_poll, forward_ready, forward_shutdown, Service, ServiceCtx};
use ntex::web::{WebRequest, WebResponse};
use libs::regex::Regex;

#[derive(Debug, Default)]
pub struct RemoveTrailingSlash;

impl<S> ntex::Middleware<S> for RemoveTrailingSlash
{
    type Service = RemoveTrailingSlashMiddleware<S>;

    fn create(&self, service: S) -> Self::Service {
        RemoveTrailingSlashMiddleware {
            service,
            merge_slash: Regex::new("//+").unwrap()
        }
    }
}

#[derive(Debug)]
pub struct RemoveTrailingSlashMiddleware<S> {
    

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ir1keren
Comment options

Answer selected by ir1keren
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants