mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
Merge pull request #42 from neon-mmd/fix-slow-speed-of-user-agent-generation
Fix slow speed of user agent generation
This commit is contained in:
commit
407925545d
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3328,6 +3328,7 @@ dependencies = [
|
|||||||
"handlebars",
|
"handlebars",
|
||||||
"log",
|
"log",
|
||||||
"md5",
|
"md5",
|
||||||
|
"once_cell",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"redis",
|
"redis",
|
||||||
"reqwest 0.11.17",
|
"reqwest 0.11.17",
|
||||||
|
@ -21,3 +21,4 @@ rlua = {version="*"}
|
|||||||
redis = {version="*"}
|
redis = {version="*"}
|
||||||
md5 = {version="*"}
|
md5 = {version="*"}
|
||||||
rand={version="*"}
|
rand={version="*"}
|
||||||
|
once_cell = {version="*"}
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
//! This module provides the functionality to generate random user agent string.
|
//! 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.
|
static USER_AGENTS: once_cell::sync::Lazy<UserAgents> = once_cell::sync::Lazy::new(|| {
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// A randomly generated user agent string.
|
|
||||||
pub fn random_user_agent() -> String {
|
|
||||||
UserAgentsBuilder::new()
|
UserAgentsBuilder::new()
|
||||||
.cache(false)
|
.cache(false)
|
||||||
.dir("/tmp")
|
.dir("/tmp")
|
||||||
@ -21,6 +16,13 @@ pub fn random_user_agent() -> String {
|
|||||||
.set_mozilla(),
|
.set_mozilla(),
|
||||||
)
|
)
|
||||||
.build()
|
.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…
Reference in New Issue
Block a user