1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00
This commit is contained in:
Rob Ede
2020-09-12 16:21:54 +01:00
committed by GitHub
parent a0ce9f28e2
commit 4d8d53cea5
145 changed files with 1011 additions and 1461 deletions

View File

@ -5,8 +5,6 @@ workspace = "../"
edition = "2018"
[dependencies]
actix-rt = "1.0"
actix-web = { version = "2.0", features = ["openssl"] }
futures = "0.3.1"
actix-web = { version = "3", features = ["openssl"] }
futures = "0.3"
openssl = "0.10"
actix-http = "1.0"

View File

@ -1,7 +1,7 @@
// <keep-alive>
use actix_web::{web, App, HttpResponse, HttpServer};
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let one = HttpServer::new(|| {
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
@ -18,6 +18,6 @@ async fn main() -> std::io::Result<()> {
})
.keep_alive(None); // <- Disable keep-alive
one.bind("127.0.0.1:8088")?.run().await
one.bind("127.0.0.1:8080")?.run().await
}
// </keep-alive>

View File

@ -8,6 +8,7 @@ async fn index(req: HttpRequest) -> HttpResponse {
.finish()
}
// </example>
// ConnectionType::Close
// ConnectionType::KeepAlive
// ConnectionType::Upgrade

View File

@ -7,12 +7,12 @@ pub mod workers;
// <main>
use actix_web::{web, App, HttpResponse, HttpServer};
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,10 +1,9 @@
// <signals>
use actix_rt::System;
use actix_web::{web, App, HttpResponse, HttpServer};
use actix_web::{web, App, HttpResponse, HttpServer, rt::System};
use std::sync::mpsc;
use std::thread;
#[actix_rt::main]
#[actix_web::main]
async fn main() {
let (tx, rx) = mpsc::channel();
@ -14,7 +13,7 @@ async fn main() {
let srv = HttpServer::new(|| {
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.shutdown_timeout(60) // <- Set shutdown timeout to 60 seconds
.run();

View File

@ -1,28 +1,28 @@
#![allow(dead_code)]
// <ssl>
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use actix_web::{get, App, HttpRequest, HttpServer, Responder};
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
#[get("/")]
async fn index(_req: HttpRequest) -> impl Responder {
"Welcome!"
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// 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();
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_openssl("127.0.0.1:8088", builder)?
HttpServer::new(|| App::new().service(index))
.bind_openssl("127.0.0.1:8080", builder)?
.run()
.await
}
// </ssl>
//
// sssl rust-tls

View File

@ -1,7 +1,7 @@
// <workers>
use actix_web::{web, App, HttpResponse, HttpServer};
#[actix_rt::main]
#[actix_web::main]
async fn main() {
HttpServer::new(|| {
App::new().route("/", web::get().to(|| HttpResponse::Ok()))