1
0
mirror of https://github.com/actix/actix-website synced 2025-02-02 04:09:06 +01:00

Update response

This commit is contained in:
Yuki Okushi 2019-12-29 02:59:48 +09:00
parent 2cd3428c8e
commit a255f4aea6
10 changed files with 49 additions and 48 deletions

View File

@ -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

View File

@ -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"

View File

@ -1,11 +1,12 @@
// <auto>
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
}
// </auto>

View File

@ -1,13 +1,14 @@
// <brotli>
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
}
// </brotli>

View File

@ -1,11 +1,12 @@
// <brotli-two>
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
}
// </brotli-two>

View File

@ -1,11 +1,12 @@
// <compress>
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
}
// </compress>

View File

@ -1,16 +1,17 @@
// <identity>
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
}
// </identity>

View File

@ -1,6 +1,6 @@
// <identity-two>
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 {
}
// </identity-two>
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
}

View File

@ -7,19 +7,19 @@ struct MyObj {
name: String,
}
fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
async fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
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
}
// </json-resp>

View File

@ -9,7 +9,7 @@ pub mod json_resp;
// <builder>
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 {
}
// </builder>
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
}