1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 15:39:02 +02:00

Updates Compression section.

This commit is contained in:
Cameron Dershem
2019-06-26 14:15:03 -04:00
parent 387807ee6e
commit 0601997b41
9 changed files with 94 additions and 29 deletions

View File

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

View File

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

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

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

View File

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

View File

@ -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();
}

View File

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