diff --git a/content/docs/http2.md b/content/docs/http2.md index 85ab4a5..51951fb 100644 --- a/content/docs/http2.md +++ b/content/docs/http2.md @@ -14,32 +14,14 @@ weight: 250 > Currently, only `rust-openssl` has support. `alpn` negotiation requires enabling the feature. When enabled, `HttpServer` provides the -[serve_tls](../../actix-web/actix_web/server/struct.HttpServer.html#method.serve_tls) method. +[bind_ssl](../../actix-web/actix_web/server/struct.HttpServer.html#method.serve_tls) method. ```toml [dependencies] -actix-web = { version = "{{< actix-version "actix-web" >}}", features = ["alpn"] } +actix-web = { version = "{{< actix-version "actix-web" >}}", features = ["ssl"] } openssl = { version = "0.10", features = ["v110"] } ``` - -```rust -use std::fs::File; -use actix_web::*; -use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype}; - -fn main() { - // load ssl keys - 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() - .resource("/index.html", |r| r.f(index))) - .bind("127.0.0.1:8080").unwrap(); - .serve_ssl(builder).unwrap(); -} -``` +{{< include-example example="http20" file="main.rs" section="main" >}} Upgrades to *HTTP/2.0* schema described in [rfc section 3.2](https://http2.github.io/http2-spec/#rfc.section.3.2) is not supported. diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 72e0df5..8abe786 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -24,4 +24,5 @@ exclude = [ "middleware", "static-files", "websockets", + "http20", ] diff --git a/examples/http20/Cargo.toml b/examples/http20/Cargo.toml new file mode 100644 index 0000000..2bf1dd4 --- /dev/null +++ b/examples/http20/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "http20" +version = "0.1.0" +authors = ["Cameron Dershem "] +edition = "2018" + +[dependencies] +actix-web = { version = "1.0", features = ["ssl"] } +openssl = { version = "0.10", features = ["v110"] } diff --git a/examples/http20/src/main.rs b/examples/http20/src/main.rs new file mode 100644 index 0000000..6395581 --- /dev/null +++ b/examples/http20/src/main.rs @@ -0,0 +1,21 @@ +//
+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 + 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(); +} +//