From a255f4aea622e6f09034599c2a942cc20b606bc9 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 29 Dec 2019 02:59:48 +0900 Subject: [PATCH] Update response --- content/docs/response.md | 4 ++-- examples/responses/Cargo.toml | 5 +++-- examples/responses/src/auto.rs | 10 +++++----- examples/responses/src/brotli.rs | 12 ++++++------ examples/responses/src/brotli_two.rs | 12 ++++++------ examples/responses/src/compress.rs | 10 +++++----- examples/responses/src/identity.rs | 12 ++++++------ examples/responses/src/identity_two.rs | 12 ++++++------ examples/responses/src/json_resp.rs | 10 +++++----- examples/responses/src/main.rs | 10 +++++----- 10 files changed, 49 insertions(+), 48 deletions(-) diff --git a/content/docs/response.md b/content/docs/response.md index 79681a1..921dffc 100644 --- a/content/docs/response.md +++ b/content/docs/response.md @@ -82,5 +82,5 @@ is enabled automatically. {{< include-example example="responses" file="chunked.rs" section="chunked" >}} -[responsebuilder]: https://docs.rs/actix-web/1.0.2/actix_web/dev/struct.HttpResponseBuilder.html -[compressmidddleware]: https://docs.rs/actix-web/1.0.2/actix_web/middleware/struct.Compress.html +[responsebuilder]: https://docs.rs/actix-web/2/actix_web/dev/struct.HttpResponseBuilder.html +[compressmidddleware]: https://docs.rs/actix-web/2/actix_web/middleware/struct.Compress.html diff --git a/examples/responses/Cargo.toml b/examples/responses/Cargo.toml index 8d5624f..ca6de1a 100644 --- a/examples/responses/Cargo.toml +++ b/examples/responses/Cargo.toml @@ -4,7 +4,8 @@ version = "1.0.0" edition = "2018" [dependencies] -actix-web = "1.0" +actix-web = "2.0" +actix-rt = "1.0" serde = "1.0" -futures = "0.1" +futures = "0.3.1" bytes = "0.4" diff --git a/examples/responses/src/auto.rs b/examples/responses/src/auto.rs index 1af1078..a1a1f15 100644 --- a/examples/responses/src/auto.rs +++ b/examples/responses/src/auto.rs @@ -1,11 +1,12 @@ // use actix_web::{http::ContentEncoding, middleware, HttpResponse}; -fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok().body("data") } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -13,9 +14,8 @@ pub fn main() { .wrap(middleware::Compress::new(ContentEncoding::Br)) .route("/", web::get().to(index)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/responses/src/brotli.rs b/examples/responses/src/brotli.rs index ebdf7e2..2f1cab1 100644 --- a/examples/responses/src/brotli.rs +++ b/examples/responses/src/brotli.rs @@ -1,13 +1,14 @@ // -use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse}; +use actix_web::{http::ContentEncoding, dev::BodyEncoding, HttpResponse}; -fn index_br() -> HttpResponse { +async fn index_br() -> HttpResponse { HttpResponse::Ok() .encoding(ContentEncoding::Br) .body("data") } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{middleware, web, App, HttpServer}; HttpServer::new(|| { @@ -15,9 +16,8 @@ pub fn main() { .wrap(middleware::Compress::default()) .route("/", web::get().to(index_br)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/responses/src/brotli_two.rs b/examples/responses/src/brotli_two.rs index cdd79f4..b7325f9 100644 --- a/examples/responses/src/brotli_two.rs +++ b/examples/responses/src/brotli_two.rs @@ -1,11 +1,12 @@ // -use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse}; +use actix_web::{http::ContentEncoding, dev::BodyEncoding, HttpResponse}; -fn index_br() -> HttpResponse { +async fn index_br() -> HttpResponse { HttpResponse::Ok().body("data") } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{middleware, web, App, HttpServer}; HttpServer::new(|| { @@ -13,9 +14,8 @@ pub fn main() { .wrap(middleware::Compress::new(ContentEncoding::Br)) .route("/", web::get().to(index_br)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/responses/src/compress.rs b/examples/responses/src/compress.rs index 105b76b..d98799b 100644 --- a/examples/responses/src/compress.rs +++ b/examples/responses/src/compress.rs @@ -1,11 +1,12 @@ // use actix_web::{middleware, HttpResponse}; -fn index_br() -> HttpResponse { +async fn index_br() -> HttpResponse { HttpResponse::Ok().body("data") } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -13,9 +14,8 @@ pub fn main() { .wrap(middleware::Compress::default()) .route("/", web::get().to(index_br)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/responses/src/identity.rs b/examples/responses/src/identity.rs index 2d759d1..0e8980a 100644 --- a/examples/responses/src/identity.rs +++ b/examples/responses/src/identity.rs @@ -1,16 +1,17 @@ // use actix_web::{ - http::ContentEncoding, middleware, middleware::BodyEncoding, HttpResponse, + http::ContentEncoding, middleware, dev::BodyEncoding, HttpResponse, }; -fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok() // v- disable compression .encoding(ContentEncoding::Identity) .body("data") } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -18,9 +19,8 @@ pub fn main() { .wrap(middleware::Compress::default()) .route("/", web::get().to(index)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/responses/src/identity_two.rs b/examples/responses/src/identity_two.rs index 62839ff..86ff64f 100644 --- a/examples/responses/src/identity_two.rs +++ b/examples/responses/src/identity_two.rs @@ -1,6 +1,6 @@ // use actix_web::{ - http::ContentEncoding, middleware, middleware::BodyEncoding, HttpResponse, + http::ContentEncoding, middleware, dev::BodyEncoding, HttpResponse, }; static HELLO_WORLD: &[u8] = &[ @@ -9,7 +9,7 @@ static HELLO_WORLD: &[u8] = &[ 0x0c, 0x00, 0x00, 0x00, ]; -pub fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok() .encoding(ContentEncoding::Identity) .header("content-encoding", "gzip") @@ -17,7 +17,8 @@ pub fn index() -> HttpResponse { } // -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -25,8 +26,7 @@ pub fn main() { .wrap(middleware::Compress::default()) .route("/", web::get().to(index)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } diff --git a/examples/responses/src/json_resp.rs b/examples/responses/src/json_resp.rs index 7fc329d..7df6796 100644 --- a/examples/responses/src/json_resp.rs +++ b/examples/responses/src/json_resp.rs @@ -7,19 +7,19 @@ struct MyObj { name: String, } -fn index(obj: web::Path) -> Result { +async fn index(obj: web::Path) -> Result { Ok(HttpResponse::Ok().json(MyObj { name: obj.name.to_string(), })) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{App, HttpServer}; HttpServer::new(|| App::new().route(r"/a/{name}", web::get().to(index))) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/responses/src/main.rs b/examples/responses/src/main.rs index d41f2b7..9ee7a55 100644 --- a/examples/responses/src/main.rs +++ b/examples/responses/src/main.rs @@ -9,7 +9,7 @@ pub mod json_resp; // use actix_web::HttpResponse; -fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok() .content_type("plain/text") .header("X-Hdr", "sample") @@ -17,12 +17,12 @@ fn index() -> HttpResponse { } // -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| App::new().route("/", web::get().to(index))) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await }