brightdata_proxy/
lib.rs

1use reqwest::Proxy;
2use typed_builder::TypedBuilder;
3use uuid::Uuid;
4
5#[derive(TypedBuilder)]
6pub struct BrightdataProxyBuilder {
7    username: String,
8    password: String,
9    #[builder(default, setter(strip_option))]
10    zone: Option<String>,
11}
12
13impl BrightdataProxyBuilder {
14    pub fn create_session(&self, session: &str) -> Result<Proxy, reqwest::Error> {
15        let mut username = self.username.to_string();
16
17        if let Some(zone) = &self.zone {
18            username.push_str("-");
19            username.push_str(zone);
20        }
21
22        username.push_str("-session-");
23        username.push_str(session);
24
25        Ok(Proxy::all("http://brd.superproxy.io:22225")?.basic_auth(&username, &self.password))
26    }
27
28    pub fn create_new_session(&self) -> Result<Proxy, reqwest::Error> {
29        let session_id = Uuid::new_v4().simple().to_string();
30        self.create_session(&session_id)
31    }
32}