1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00
This commit is contained in:
Rob Ede
2020-09-12 16:21:54 +01:00
committed by GitHub
parent a0ce9f28e2
commit 4d8d53cea5
145 changed files with 1011 additions and 1461 deletions

View File

@ -4,8 +4,7 @@ version = "1.0.0"
edition = "2018"
[dependencies]
actix-web = "2.0"
actix-rt = "1.0"
actix-web = "3"
serde = "1.0"
futures = "0.3.1"
bytes = "0.5"

View File

@ -1,20 +1,19 @@
// <auto>
use actix_web::{http::ContentEncoding, middleware, HttpResponse};
use actix_web::{get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer};
#[get("/")]
async fn index() -> HttpResponse {
HttpResponse::Ok().body("data")
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| {
App::new()
.wrap(middleware::Compress::new(ContentEncoding::Br))
.route("/", web::get().to(index))
.service(index)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,22 +1,23 @@
// <brotli>
use actix_web::{http::ContentEncoding, dev::BodyEncoding, HttpResponse};
use actix_web::{
dev::BodyEncoding, get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer,
};
#[get("/")]
async fn index_br() -> HttpResponse {
HttpResponse::Ok()
.encoding(ContentEncoding::Br)
.body("data")
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{middleware, web, App, HttpServer};
HttpServer::new(|| {
App::new()
.wrap(middleware::Compress::default())
.route("/", web::get().to(index_br))
.service(index_br)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -5,7 +5,7 @@ async fn index_br() -> HttpResponse {
HttpResponse::Ok().body("data")
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{middleware, web, App, HttpServer};
@ -14,7 +14,7 @@ async fn main() -> std::io::Result<()> {
.wrap(middleware::Compress::new(ContentEncoding::Br))
.route("/", web::get().to(index_br))
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,20 +1,19 @@
// <chunked>
use actix_web::{HttpRequest, HttpResponse, Error};
use actix_web::{get, App, Error, HttpRequest, HttpResponse, HttpServer};
use bytes::Bytes;
use futures::future::ok;
use futures::stream::once;
async fn index(req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.streaming(once(ok::<_, Error>(Bytes::from_static(b"data"))))
#[get("/")]
async fn index(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok().streaming(once(ok::<_, Error>(Bytes::from_static(b"data"))))
}
// </chunked>
pub fn main() {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| App::new().route("/", web::get().to(index)))
.bind("127.0.0.1:8088")
#[actix_web::main]
async fn main() {
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")
.unwrap()
.run();
}

View File

@ -1,20 +1,19 @@
// <compress>
use actix_web::{middleware, HttpResponse};
use actix_web::{get, middleware, App, HttpResponse, HttpServer};
#[get("/")]
async fn index_br() -> HttpResponse {
HttpResponse::Ok().body("data")
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| {
App::new()
.wrap(middleware::Compress::default())
.route("/", web::get().to(index_br))
.service(index_br)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,8 +1,9 @@
// <identity>
use actix_web::{
http::ContentEncoding, middleware, dev::BodyEncoding, HttpResponse,
dev::BodyEncoding, get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer,
};
#[get("/")]
async fn index() -> HttpResponse {
HttpResponse::Ok()
// v- disable compression
@ -10,16 +11,14 @@ async fn index() -> HttpResponse {
.body("data")
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| {
App::new()
.wrap(middleware::Compress::default())
.route("/", web::get().to(index))
.service(index)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,14 +1,14 @@
// <identity-two>
use actix_web::{
http::ContentEncoding, middleware, dev::BodyEncoding, HttpResponse,
dev::BodyEncoding, get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer,
};
static HELLO_WORLD: &[u8] = &[
0x1f, 0x8b, 0x08, 0x00, 0xa2, 0x30, 0x10, 0x5c, 0x00, 0x03, 0xcb, 0x48, 0xcd, 0xc9,
0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf,
0x0c, 0x00, 0x00, 0x00,
0x1f, 0x8b, 0x08, 0x00, 0xa2, 0x30, 0x10, 0x5c, 0x00, 0x03, 0xcb, 0x48, 0xcd, 0xc9, 0xc9, 0x57,
0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00, 0x00, 0x00,
];
#[get("/")]
async fn index() -> HttpResponse {
HttpResponse::Ok()
.encoding(ContentEncoding::Identity)
@ -17,16 +17,14 @@ async fn index() -> HttpResponse {
}
// </identity-two>
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| {
App::new()
.wrap(middleware::Compress::default())
.route("/", web::get().to(index))
.service(index)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,5 +1,5 @@
// <json-resp>
use actix_web::{web, HttpResponse, Result};
use actix_web::{get, web, HttpResponse, Result};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
@ -7,18 +7,19 @@ struct MyObj {
name: String,
}
#[get("/a/{name}")]
async fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
Ok(HttpResponse::Ok().json(MyObj {
name: obj.name.to_string(),
}))
}
#[actix_rt::main]
#[actix_web::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")?
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -17,12 +17,12 @@ async fn index() -> HttpResponse {
}
// </builder>
#[actix_rt::main]
#[actix_web::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")?
.bind("127.0.0.1:8080")?
.run()
.await
}