fix: reduce the time to build user-agents
This commit is contained in:
parent
5f052dbee8
commit
6e19246cb2
3 changed files with 13 additions and 9 deletions
|
@ -1,13 +1,8 @@
|
|||
//! This module provides the functionality to generate random user agent string.
|
||||
|
||||
use fake_useragent::{Browsers, UserAgentsBuilder};
|
||||
use fake_useragent::{Browsers, UserAgents, UserAgentsBuilder};
|
||||
|
||||
/// 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 {
|
||||
static USER_AGENTS: once_cell::sync::Lazy<UserAgents> = once_cell::sync::Lazy::new(|| {
|
||||
UserAgentsBuilder::new()
|
||||
.cache(false)
|
||||
.dir("/tmp")
|
||||
|
@ -21,6 +16,13 @@ pub fn random_user_agent() -> String {
|
|||
.set_mozilla(),
|
||||
)
|
||||
.build()
|
||||
.random()
|
||||
.to_string()
|
||||
});
|
||||
|
||||
/// 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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue