Skip to content

Lowercase query with 301 redirect #1817

Answered by max-frai
max-frai asked this question in Q&A
Discussion options

You must be logged in to vote

In case someone also searching for this, here is complete middleware:

use std::task::{Context, Poll};

use actix_service::{Service, Transform};
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::{http, Error, HttpResponse};
use futures::future::{ok, Either, Ready};

pub struct LowercaseRequest;

impl<S, B> Transform<S> for LowercaseRequest
where
    S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
    S::Future: 'static,
{
    type Request = ServiceRequest;
    type Response = ServiceResponse<B>;
    type Error = Error;
    type InitError = ();
    type Transform = LowercaseRequestMiddleware<S>;
    type Future = Ready<Result<Self::Tra…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by max-frai
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
Converted from issue

This discussion was converted from issue #1817 on December 08, 2020 17:54.