Crates.io | actix-web-middleware-redirect-https |
lib.rs | actix-web-middleware-redirect-https |
version | 3.0.1 |
source | src |
created_at | 2019-11-06 13:25:43.09193 |
updated_at | 2021-03-15 13:26:48.493421 |
description | A middleware for actix-web which forwards all `http` requests to `https` with optional url string replacement. |
homepage | |
repository | https://github.com/petertrotman/actix-web-middleware-redirect-https |
max_upload_size | |
id | 178638 |
size | 8,986 |
A middleware for actix-web which forwards all http
requests to https
with optional url string replacement.
Note: Consider using this fork instead
# 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!")));