MCPcopy Create free account
hub / github.com/actix/examples / fetch_image

Function fetch_image

https-tls/awc-https/src/main.rs:10–36  ·  view source on GitHub ↗
(client: ThinData<Client>)

Source from the content-addressed store, hash-verified

8
9#[get("/")]
10async fn fetch_image(client: ThinData<Client>) -> HttpResponse {
11 let start = Instant::now();
12
13 let mut res = client.get(MAP_URL).send().await.unwrap();
14
15 if !res.status().is_success() {
16 log::error!("Wikipedia did not return expected image");
17 return HttpResponse::InternalServerError().finish();
18 }
19
20 let payload = res
21 .body()
22 // expected image is larger than default body limit, set up a higher
23 // limit of 20 MB
24 .limit(20_000_000)
25 .await
26 .unwrap();
27
28 log::info!(
29 "It took {}ms to download image to memory",
30 start.elapsed().as_millis()
31 );
32
33 HttpResponse::Ok()
34 .content_type(mime::IMAGE_JPEG)
35 .body(payload)
36}
37
38#[actix_web::main]
39async fn main() -> std::io::Result<()> {

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected