2023-04-27 10:53:28 -04:00
|
|
|
//! This module provides the functionality to generate random user agent string.
|
|
|
|
|
2023-05-22 06:07:37 -04:00
|
|
|
use fake_useragent::{Browsers, UserAgents, UserAgentsBuilder};
|
2023-04-25 09:30:04 -04:00
|
|
|
|
2023-05-22 06:07:37 -04:00
|
|
|
static USER_AGENTS: once_cell::sync::Lazy<UserAgents> = once_cell::sync::Lazy::new(|| {
|
2023-04-25 09:30:04 -04:00
|
|
|
UserAgentsBuilder::new()
|
|
|
|
.cache(false)
|
|
|
|
.dir("/tmp")
|
|
|
|
.thread(1)
|
|
|
|
.set_browsers(
|
|
|
|
Browsers::new()
|
|
|
|
.set_chrome()
|
|
|
|
.set_safari()
|
|
|
|
.set_edge()
|
|
|
|
.set_firefox()
|
|
|
|
.set_mozilla(),
|
|
|
|
)
|
|
|
|
.build()
|
2023-05-22 06:07:37 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
/// A function to generate random user agent to improve privacy of the user.
|
|
|
|
///
|
|
|
|
/// # Returns
|
|
|
|
///
|
|
|
|
/// A randomly generated user agent string.
|
|
|
|
pub fn random_user_agent() -> String {
|
|
|
|
USER_AGENTS.random().to_string()
|
2023-04-25 09:30:04 -04:00
|
|
|
}
|