mirror of
https://github.com/actix/actix-website
synced 2024-11-27 18:12:57 +01:00
Update server
This commit is contained in:
parent
a255f4aea6
commit
e21219c1da
@ -12,7 +12,7 @@ The [**HttpServer**][httpserverstruct] type is responsible for serving http requ
|
||||
must have `Send` + `Sync` boundaries. More about that in the *multi-threading* section.
|
||||
|
||||
To bind to a specific socket address, [`bind()`][bindmethod] must be used, and it may be
|
||||
called multiple times. To bind ssl socket, [`bind_ssl()`][bindsslmethod] or
|
||||
called multiple times. To bind ssl socket, [`bind_openssl()`][bindopensslmethod] or
|
||||
[`bind_rustls()`][bindrusttls] should be used. To start the http server, use one of the
|
||||
start methods.
|
||||
|
||||
@ -117,13 +117,13 @@ are available on unix systems.
|
||||
> It is possible to disable signal handling with
|
||||
[`HttpServer::disable_signals()`][disablesignals] method.
|
||||
|
||||
[httpserverstruct]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html
|
||||
[bindmethod]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html#method.bind
|
||||
[bindsslmethod]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html#method.bind_ssl
|
||||
[bindrusttls]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html#method.bind_rustls
|
||||
[startmethod]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html#method.start
|
||||
[workers]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html#method.workers
|
||||
[httpserverstruct]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html
|
||||
[bindmethod]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html#method.bind
|
||||
[bindopensslmethod]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html#method.bind_openssl
|
||||
[bindrusttls]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html#method.bind_rustls
|
||||
[startmethod]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html#method.start
|
||||
[workers]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html#method.workers
|
||||
[tlsalpn]: https://tools.ietf.org/html/rfc7301
|
||||
[exampletls]: https://github.com/actix/examples/tree/master/tls
|
||||
[shutdowntimeout]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html#method.shutdown_timeout
|
||||
[disablesignals]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpServer.html#method.disable_signals
|
||||
[shutdowntimeout]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html#method.shutdown_timeout
|
||||
[disablesignals]: https://docs.rs/actix-web/2/actix_web/struct.HttpServer.html#method.disable_signals
|
||||
|
@ -5,8 +5,8 @@ workspace = "../"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-rt = "0.2"
|
||||
actix-web = { version = "1.0", features = ["ssl"] }
|
||||
futures = "0.1"
|
||||
actix-rt = "1.0"
|
||||
actix-web = { version = "2.0", features = ["openssl"] }
|
||||
futures = "0.3.1"
|
||||
openssl = "0.10"
|
||||
actix-http = "0.2"
|
||||
actix-http = "1.0"
|
||||
|
@ -1,7 +1,8 @@
|
||||
// <keep-alive>
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
|
||||
pub fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let one = HttpServer::new(|| {
|
||||
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
|
||||
})
|
||||
@ -17,6 +18,6 @@ pub fn main() {
|
||||
})
|
||||
.keep_alive(None); // <- Disable keep-alive
|
||||
|
||||
one.bind("127.0.0.1:8088").unwrap().run().unwrap();
|
||||
one.bind("127.0.0.1:8088")?.run().await
|
||||
}
|
||||
// </keep-alive>
|
||||
|
@ -1,7 +1,7 @@
|
||||
// <example>
|
||||
use actix_web::{http, HttpRequest, HttpResponse};
|
||||
|
||||
pub fn index(req: HttpRequest) -> HttpResponse {
|
||||
async fn index(req: HttpRequest) -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.connection_type(http::ConnectionType::Close) // <- Close connection
|
||||
.force_close() // <- Alternative method
|
||||
|
@ -7,16 +7,13 @@ pub mod workers;
|
||||
// <main>
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
|
||||
fn main() {
|
||||
let sys = actix_rt::System::new("example");
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.start();
|
||||
|
||||
let _ = sys.run();
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
// </main>
|
||||
|
@ -1,7 +1,5 @@
|
||||
use actix_rt;
|
||||
use futures::Future;
|
||||
|
||||
// <signals>
|
||||
use actix_rt::System;
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
@ -10,7 +8,7 @@ pub fn main() {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
thread::spawn(move || {
|
||||
let sys = actix_rt::System::new("http-server");
|
||||
let sys = System::new("http-server");
|
||||
|
||||
let addr = HttpServer::new(|| {
|
||||
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
|
||||
@ -18,24 +16,17 @@ pub fn main() {
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.shutdown_timeout(60) // <- Set shutdown timeout to 60 seconds
|
||||
.start();
|
||||
.run();
|
||||
|
||||
let _ = tx.send(addr);
|
||||
let _ = sys.run();
|
||||
});
|
||||
|
||||
let addr = rx.recv().unwrap();
|
||||
let _ = addr
|
||||
.pause()
|
||||
.wait()
|
||||
.map(|_| println!("`actix_server::ServerCommand::Pause`"));
|
||||
let _ = addr
|
||||
.resume()
|
||||
.wait()
|
||||
.map(|_| println!("`actix_server::ServerCommand::Resume`"));
|
||||
let _ = addr
|
||||
.stop(true)
|
||||
.wait()
|
||||
.map(|_| println!("`actix_server::ServerCommand::Stop`"));
|
||||
let _ = System::new("`actix_server::ServerCommand::Pause`")
|
||||
.block_on(addr.pause());
|
||||
let _ = System::new("`actix_server::ServerCommand::Resume`")
|
||||
.block_on(addr.resume());
|
||||
let _ = System::new("`actix_server::ServerCommand::Stop`")
|
||||
.block_on(addr.stop(true));
|
||||
}
|
||||
// </signals>
|
||||
|
@ -2,11 +2,12 @@
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||
|
||||
fn index(_req: HttpRequest) -> impl Responder {
|
||||
async fn index(_req: HttpRequest) -> impl Responder {
|
||||
"Welcome!"
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
#[actix_rt::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'`
|
||||
@ -18,10 +19,9 @@ pub fn main() {
|
||||
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()
|
||||
.bind_openssl("127.0.0.1:8088", builder)?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </ssl>
|
||||
//
|
||||
|
@ -1,7 +1,8 @@
|
||||
// <workers>
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
|
||||
pub fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() {
|
||||
HttpServer::new(|| {
|
||||
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user