#actix-web #middleware #redirect #https #ssl

actix-web-middleware-redirect-https

A middleware for actix-web which forwards all http requests to https with optional url string replacement

5 releases (3 stable)

3.0.1 Mar 15, 2021
1.0.0 Jan 22, 2020
0.1.1 Nov 6, 2019
0.1.0 Nov 6, 2019

#215 in HTTP server

Download history 127/week @ 2022-03-05 92/week @ 2022-03-12 74/week @ 2022-03-19 70/week @ 2022-03-26 31/week @ 2022-04-02 83/week @ 2022-04-09 41/week @ 2022-04-16 19/week @ 2022-04-23 16/week @ 2022-04-30 60/week @ 2022-05-07 107/week @ 2022-05-14 31/week @ 2022-05-21 53/week @ 2022-05-28 49/week @ 2022-06-04 11/week @ 2022-06-11 17/week @ 2022-06-18

134 downloads per month
Used in lupt

MIT license

7KB
71 lines

actix-web-middleware-redirect-https

Build Status

A middleware for actix-web which forwards all http requests to https with optional url string replacement.

Note: Consider using this fork instead

crates.io

docs.rs

Usage

# Cargo.toml
[dependencies]
actix-web-middleware-redirect-https = "3.0.1"
use actix_web::{App, web, HttpResponse};
use actix_web_middleware_redirect_https::RedirectHTTPS;

App::new()
    .wrap(RedirectHTTPS::default())
    .route("/", web::get().to(|| HttpResponse::Ok()
                                    .content_type("text/plain")
                                    .body("Always HTTPS!")));

By default, the middleware simply replaces the scheme of the URL with https://, but you may need to it to change other parts of the URL. For example, in development if you are not using the default ports (80 and 443) then you will need to specify their replacement, as below:

use actix_web::{App, web, HttpResponse};
use actix_web_middleware_redirect_https::RedirectHTTPS;

App::new()
    .wrap(RedirectHTTPS::with_replacements(&[(":8080".to_owned(), ":8443".to_owned())]))
    .route("/", web::get().to(|| HttpResponse::Ok()
                                    .content_type("text/plain")
                                    .body("Always HTTPS on non-default ports!")));

Dependencies

~22MB
~509K SLoC