mirror of
https://github.com/actix/examples
synced 2025-06-28 18:00:37 +02:00
Restructure folders (#411)
This commit is contained in:
committed by
GitHub
parent
9db98162b2
commit
c3407627d0
42
security/awc_https/src/main.rs
Normal file
42
security/awc_https/src/main.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use actix_web::{
|
||||
client::{Client, Connector},
|
||||
web, App, HttpRequest, HttpResponse, HttpServer,
|
||||
};
|
||||
use openssl::ssl::{SslConnector, SslMethod};
|
||||
|
||||
async fn index(_req: HttpRequest) -> HttpResponse {
|
||||
let builder = SslConnector::builder(SslMethod::tls()).unwrap();
|
||||
|
||||
let client = Client::builder()
|
||||
.connector(Connector::new().ssl(builder.build()).finish())
|
||||
.finish();
|
||||
|
||||
let now = std::time::Instant::now();
|
||||
let payload =
|
||||
client
|
||||
.get("https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg")
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.body()
|
||||
.limit(20_000_000) // sets max allowable payload size
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!(
|
||||
"awc time elapsed while reading bytes into memory: {} ms",
|
||||
now.elapsed().as_millis()
|
||||
);
|
||||
|
||||
HttpResponse::Ok().content_type("image/jpeg").body(payload)
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let port = 3000;
|
||||
|
||||
HttpServer::new(|| App::new().service(web::resource("/").to(index)))
|
||||
.bind(("0.0.0.0", port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
Reference in New Issue
Block a user