mirror of
https://github.com/actix/actix-website
synced 2025-06-27 07:29:02 +02:00
Updates Compression section.
This commit is contained in:
@ -10,8 +10,7 @@ pub fn main() {
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
// v- disable compression for all routes
|
||||
.wrap(middleware::Compress::new(ContentEncoding::Identity))
|
||||
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
||||
.route("/", web::get().to(index))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
|
@ -6,14 +6,18 @@ fn index_br() -> HttpResponse {
|
||||
.encoding(ContentEncoding::Br)
|
||||
.body("data")
|
||||
}
|
||||
// </brotli>
|
||||
|
||||
pub fn main() {
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use actix_web::{middleware, web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index_br)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(middleware::Compress::default())
|
||||
.route("/", web::get().to(index_br))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </brotli>
|
||||
|
21
examples/responses/src/brotli_two.rs
Normal file
21
examples/responses/src/brotli_two.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// <brotli-two>
|
||||
use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse};
|
||||
|
||||
fn index_br() -> HttpResponse {
|
||||
HttpResponse::Ok().body("data")
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
use actix_web::{middleware, web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
||||
.route("/", web::get().to(index_br))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </brotli-two>
|
21
examples/responses/src/compress.rs
Normal file
21
examples/responses/src/compress.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// <compress>
|
||||
use actix_web::{http::ContentEncoding, middleware, HttpResponse};
|
||||
|
||||
fn index_br() -> HttpResponse {
|
||||
HttpResponse::Ok().body("data")
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(middleware::Compress::default())
|
||||
.route("/", web::get().to(index_br))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </compress>
|
@ -1,5 +1,7 @@
|
||||
// <identity>
|
||||
use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse};
|
||||
use actix_web::{
|
||||
http::ContentEncoding, middleware, middleware::BodyEncoding, HttpResponse,
|
||||
};
|
||||
|
||||
fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
@ -7,14 +9,18 @@ fn index() -> HttpResponse {
|
||||
.encoding(ContentEncoding::Identity)
|
||||
.body("data")
|
||||
}
|
||||
// </identity>
|
||||
|
||||
pub fn main() {
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(middleware::Compress::default())
|
||||
.route("/", web::get().to(index))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </identity>
|
||||
|
@ -1,6 +1,7 @@
|
||||
// <identity-two>
|
||||
use actix_web::{
|
||||
http::ContentEncoding, middleware::BodyEncoding, HttpRequest, HttpResponse,
|
||||
http::ContentEncoding, middleware, middleware::BodyEncoding, HttpRequest,
|
||||
HttpResponse,
|
||||
};
|
||||
|
||||
static HELLO_WORLD: &[u8] = &[
|
||||
@ -20,9 +21,13 @@ pub fn index(_req: HttpRequest) -> HttpResponse {
|
||||
pub fn main() {
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(middleware::Compress::default())
|
||||
.route("/", web::get().to(index))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
pub mod auto;
|
||||
pub mod brotli;
|
||||
pub mod chunked;
|
||||
pub mod compress;
|
||||
pub mod identity;
|
||||
pub mod identity_two;
|
||||
pub mod json_resp;
|
||||
|
Reference in New Issue
Block a user