mirror of
https://github.com/actix/actix-website
synced 2025-02-08 22:36:07 +01:00
Update response
This commit is contained in:
parent
2cd3428c8e
commit
a255f4aea6
@ -82,5 +82,5 @@ is enabled automatically.
|
|||||||
|
|
||||||
{{< include-example example="responses" file="chunked.rs" section="chunked" >}}
|
{{< include-example example="responses" file="chunked.rs" section="chunked" >}}
|
||||||
|
|
||||||
[responsebuilder]: https://docs.rs/actix-web/1.0.2/actix_web/dev/struct.HttpResponseBuilder.html
|
[responsebuilder]: https://docs.rs/actix-web/2/actix_web/dev/struct.HttpResponseBuilder.html
|
||||||
[compressmidddleware]: https://docs.rs/actix-web/1.0.2/actix_web/middleware/struct.Compress.html
|
[compressmidddleware]: https://docs.rs/actix-web/2/actix_web/middleware/struct.Compress.html
|
||||||
|
@ -4,7 +4,8 @@ version = "1.0.0"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "1.0"
|
actix-web = "2.0"
|
||||||
|
actix-rt = "1.0"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
futures = "0.1"
|
futures = "0.3.1"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
// <auto>
|
// <auto>
|
||||||
use actix_web::{http::ContentEncoding, middleware, HttpResponse};
|
use actix_web::{http::ContentEncoding, middleware, HttpResponse};
|
||||||
|
|
||||||
fn index() -> HttpResponse {
|
async fn index() -> HttpResponse {
|
||||||
HttpResponse::Ok().body("data")
|
HttpResponse::Ok().body("data")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
@ -13,9 +14,8 @@ pub fn main() {
|
|||||||
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
||||||
.route("/", web::get().to(index))
|
.route("/", web::get().to(index))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </auto>
|
// </auto>
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
// <brotli>
|
// <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()
|
HttpResponse::Ok()
|
||||||
.encoding(ContentEncoding::Br)
|
.encoding(ContentEncoding::Br)
|
||||||
.body("data")
|
.body("data")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{middleware, web, App, HttpServer};
|
use actix_web::{middleware, web, App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
@ -15,9 +16,8 @@ pub fn main() {
|
|||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.route("/", web::get().to(index_br))
|
.route("/", web::get().to(index_br))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </brotli>
|
// </brotli>
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
// <brotli-two>
|
// <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")
|
HttpResponse::Ok().body("data")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{middleware, web, App, HttpServer};
|
use actix_web::{middleware, web, App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
@ -13,9 +14,8 @@ pub fn main() {
|
|||||||
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
||||||
.route("/", web::get().to(index_br))
|
.route("/", web::get().to(index_br))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </brotli-two>
|
// </brotli-two>
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
// <compress>
|
// <compress>
|
||||||
use actix_web::{middleware, HttpResponse};
|
use actix_web::{middleware, HttpResponse};
|
||||||
|
|
||||||
fn index_br() -> HttpResponse {
|
async fn index_br() -> HttpResponse {
|
||||||
HttpResponse::Ok().body("data")
|
HttpResponse::Ok().body("data")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
@ -13,9 +14,8 @@ pub fn main() {
|
|||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.route("/", web::get().to(index_br))
|
.route("/", web::get().to(index_br))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </compress>
|
// </compress>
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
// <identity>
|
// <identity>
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
http::ContentEncoding, middleware, middleware::BodyEncoding, HttpResponse,
|
http::ContentEncoding, middleware, dev::BodyEncoding, HttpResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn index() -> HttpResponse {
|
async fn index() -> HttpResponse {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
// v- disable compression
|
// v- disable compression
|
||||||
.encoding(ContentEncoding::Identity)
|
.encoding(ContentEncoding::Identity)
|
||||||
.body("data")
|
.body("data")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
@ -18,9 +19,8 @@ pub fn main() {
|
|||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.route("/", web::get().to(index))
|
.route("/", web::get().to(index))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </identity>
|
// </identity>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// <identity-two>
|
// <identity-two>
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
http::ContentEncoding, middleware, middleware::BodyEncoding, HttpResponse,
|
http::ContentEncoding, middleware, dev::BodyEncoding, HttpResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
static HELLO_WORLD: &[u8] = &[
|
static HELLO_WORLD: &[u8] = &[
|
||||||
@ -9,7 +9,7 @@ static HELLO_WORLD: &[u8] = &[
|
|||||||
0x0c, 0x00, 0x00, 0x00,
|
0x0c, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn index() -> HttpResponse {
|
async fn index() -> HttpResponse {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.encoding(ContentEncoding::Identity)
|
.encoding(ContentEncoding::Identity)
|
||||||
.header("content-encoding", "gzip")
|
.header("content-encoding", "gzip")
|
||||||
@ -17,7 +17,8 @@ pub fn index() -> HttpResponse {
|
|||||||
}
|
}
|
||||||
// </identity-two>
|
// </identity-two>
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
@ -25,8 +26,7 @@ pub fn main() {
|
|||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.route("/", web::get().to(index))
|
.route("/", web::get().to(index))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,19 @@ struct MyObj {
|
|||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
|
async fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
|
||||||
Ok(HttpResponse::Ok().json(MyObj {
|
Ok(HttpResponse::Ok().json(MyObj {
|
||||||
name: obj.name.to_string(),
|
name: obj.name.to_string(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{App, HttpServer};
|
use actix_web::{App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| App::new().route(r"/a/{name}", web::get().to(index)))
|
HttpServer::new(|| App::new().route(r"/a/{name}", web::get().to(index)))
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </json-resp>
|
// </json-resp>
|
||||||
|
@ -9,7 +9,7 @@ pub mod json_resp;
|
|||||||
// <builder>
|
// <builder>
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
|
|
||||||
fn index() -> HttpResponse {
|
async fn index() -> HttpResponse {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("plain/text")
|
.content_type("plain/text")
|
||||||
.header("X-Hdr", "sample")
|
.header("X-Hdr", "sample")
|
||||||
@ -17,12 +17,12 @@ fn index() -> HttpResponse {
|
|||||||
}
|
}
|
||||||
// </builder>
|
// </builder>
|
||||||
|
|
||||||
pub fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
|
|
||||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user