mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
fix cd links
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# middleware examples
|
||||
# Middleware: Add/Retrieve Request-Local Data
|
||||
|
||||
This example showcases a middleware that adds and retrieves request-local data. See also the [Middleware guide](https://actix.rs/docs/middleware/).
|
||||
This example showcases a middleware that adds and retrieves request-local data. See also the [middleware guide](https://actix.rs/docs/middleware/).
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
## Middleware eg - redirect any http connection to use https connection
|
||||
## Middleware: Redirect Any HTTP Connection To Use HTTPS Connection
|
||||
|
||||
This example is the next step after implementing this example : [Setup TLS via rustls](https://github.com/actix/examples/tree/master/security/rustls).
|
||||
|
||||
You might have already implemented TLS(using one of the ways mentioned in the example of security section), and have setup your server to listen to port 443(for https).
|
||||
You might have already implemented TLS (using one of the ways mentioned in the example of security section), and have setup your server to listen to port 443 (for HTTPS).
|
||||
|
||||
Now, the only problem left to solve is, to listen to **http** connections as well and redirect them to use **https**
|
||||
Now, the only problem left to solve is, to listen to **HTTP** connections as well and redirect them to use **HTTPS**
|
||||
|
||||
## Usage
|
||||
|
||||
**Note :** You will be required to use sudo while running the binary to access port 80 and 443
|
||||
## Notes
|
||||
|
||||
Also see [`redirect_to_https`](https://docs.rs/actix-web-lab/0/actix_web_lab/middleware/fn.redirect_to_https.html) from [`actix-web-lab`](https://crates.io/crates/actix-web-lab).
|
||||
|
@ -1,13 +1,7 @@
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use actix_web::dev::Service;
|
||||
use futures::future::FutureExt;
|
||||
|
||||
use actix_web::{get, App, HttpServer};
|
||||
use actix_web::{http, HttpResponse};
|
||||
use futures::future;
|
||||
use futures::future::Either;
|
||||
use actix_web::{dev::Service, get, http, App, HttpResponse, HttpServer};
|
||||
use futures::future::{self, Either, FutureExt};
|
||||
use rustls::{Certificate, PrivateKey, ServerConfig};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
|
||||
@ -65,8 +59,8 @@ async fn main() -> std::io::Result<()> {
|
||||
})
|
||||
.service(index)
|
||||
})
|
||||
.bind("0.0.0.0:80")? // Port 80 to listen for http request
|
||||
.bind_rustls("0.0.0.0:443", config)? // Port 443 to listen for https request
|
||||
.bind("127.0.0.1:80")? // Port 80 to listen for HTTP request
|
||||
.bind_rustls("127.0.0.1:443", config)? // Port 443 to listen for HTTPS request
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user