Skip to main content

freya_components/
http.rs

1use freya_core::prelude::*;
2use reqwest::blocking::Client;
3
4/// Shared blocking HTTP client used to fetch remote assets.
5pub(crate) struct Http;
6
7impl Http {
8    /// Returns the shared [`Client`], lazily creating it in the root context on first use.
9    pub(crate) fn get() -> Client {
10        try_consume_root_context::<Client>().unwrap_or_else(|| {
11            let client = Client::builder()
12                .build()
13                .expect("Failed to build the HTTP client.");
14            provide_root_context(client.clone());
15            client
16        })
17    }
18}