2020-04-03 09:16:17 +02:00
|
|
|
use actix_web::{
|
|
|
|
client::{Client, Connector},
|
|
|
|
web, App, HttpRequest, HttpResponse, HttpServer,
|
|
|
|
};
|
2020-03-01 19:16:57 +01:00
|
|
|
use openssl::ssl::{SslConnector, SslMethod};
|
2020-03-01 14:55:00 +01:00
|
|
|
|
2020-04-03 09:14:30 +02:00
|
|
|
async fn index(_req: HttpRequest) -> HttpResponse {
|
2020-04-03 09:16:17 +02:00
|
|
|
let builder = SslConnector::builder(SslMethod::tls()).unwrap();
|
2020-03-01 14:55:00 +01:00
|
|
|
|
2020-09-12 17:49:45 +02:00
|
|
|
let client = Client::builder()
|
2020-03-01 14:55:00 +01:00
|
|
|
.connector(Connector::new().ssl(builder.build()).finish())
|
|
|
|
.finish();
|
|
|
|
|
2020-04-03 09:16:17 +02:00
|
|
|
let now = std::time::Instant::now();
|
2020-03-01 14:55:00 +01:00
|
|
|
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();
|
|
|
|
|
2020-04-03 09:16:17 +02:00
|
|
|
println!(
|
|
|
|
"awc time elapsed while reading bytes into memory: {} ms",
|
|
|
|
now.elapsed().as_millis()
|
|
|
|
);
|
2020-03-01 14:55:00 +01:00
|
|
|
|
2020-04-03 09:16:17 +02:00
|
|
|
HttpResponse::Ok().content_type("image/jpeg").body(payload)
|
2020-03-01 14:55:00 +01:00
|
|
|
}
|
|
|
|
|
2020-09-12 17:49:45 +02:00
|
|
|
#[actix_web::main]
|
2020-03-01 14:55:00 +01:00
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
let port = 3000;
|
|
|
|
|
2020-04-03 09:16:17 +02:00
|
|
|
HttpServer::new(|| App::new().service(web::resource("/").to(index)))
|
|
|
|
.bind(("0.0.0.0", port))?
|
|
|
|
.run()
|
|
|
|
.await
|
2020-03-01 14:55:00 +01:00
|
|
|
}
|