mirror of
https://github.com/actix/actix-website
synced 2025-06-27 07:29:02 +02:00
Updates http2 chapter after testing.
This commit is contained in:
8
examples/http2/Cargo.toml
Normal file
8
examples/http2/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "http2"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = { version = "1.0", features = ["ssl"] }
|
||||
openssl = { version = "0.10", features = ["v110"] }
|
25
examples/http2/src/main.rs
Normal file
25
examples/http2/src/main.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// <main>
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||
|
||||
fn index(_req: HttpRequest) -> impl Responder {
|
||||
"Hello."
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// load ssl keys
|
||||
// to create a self-signed temporary cert for testing:
|
||||
// `openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'`
|
||||
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
|
||||
builder
|
||||
.set_private_key_file("key.pem", SslFiletype::PEM)
|
||||
.unwrap();
|
||||
builder.set_certificate_chain_file("cert.pem").unwrap();
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
.bind_ssl("127.0.0.1:8088", builder)
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </main>
|
Reference in New Issue
Block a user