neon_arch
commited on
Commit
•
6e19246
1
Parent(s):
5f052db
fix: reduce the time to build user-agents
Browse files- Cargo.lock +1 -0
- Cargo.toml +1 -0
- src/search_results_handler/user_agent.rs +11 -9
Cargo.lock
CHANGED
@@ -3328,6 +3328,7 @@ dependencies = [
|
|
3328 |
"handlebars",
|
3329 |
"log",
|
3330 |
"md5",
|
|
|
3331 |
"rand 0.8.5",
|
3332 |
"redis",
|
3333 |
"reqwest 0.11.17",
|
|
|
3328 |
"handlebars",
|
3329 |
"log",
|
3330 |
"md5",
|
3331 |
+
"once_cell",
|
3332 |
"rand 0.8.5",
|
3333 |
"redis",
|
3334 |
"reqwest 0.11.17",
|
Cargo.toml
CHANGED
@@ -21,3 +21,4 @@ rlua = {version="*"}
|
|
21 |
redis = {version="*"}
|
22 |
md5 = {version="*"}
|
23 |
rand={version="*"}
|
|
|
|
21 |
redis = {version="*"}
|
22 |
md5 = {version="*"}
|
23 |
rand={version="*"}
|
24 |
+
once_cell = {version="*"}
|
src/search_results_handler/user_agent.rs
CHANGED
@@ -1,13 +1,8 @@
|
|
1 |
//! This module provides the functionality to generate random user agent string.
|
2 |
|
3 |
-
use fake_useragent::{Browsers, UserAgentsBuilder};
|
4 |
|
5 |
-
|
6 |
-
///
|
7 |
-
/// # Returns
|
8 |
-
///
|
9 |
-
/// A randomly generated user agent string.
|
10 |
-
pub fn random_user_agent() -> String {
|
11 |
UserAgentsBuilder::new()
|
12 |
.cache(false)
|
13 |
.dir("/tmp")
|
@@ -21,6 +16,13 @@ pub fn random_user_agent() -> String {
|
|
21 |
.set_mozilla(),
|
22 |
)
|
23 |
.build()
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
|
|
1 |
//! This module provides the functionality to generate random user agent string.
|
2 |
|
3 |
+
use fake_useragent::{Browsers, UserAgents, UserAgentsBuilder};
|
4 |
|
5 |
+
static USER_AGENTS: once_cell::sync::Lazy<UserAgents> = once_cell::sync::Lazy::new(|| {
|
|
|
|
|
|
|
|
|
|
|
6 |
UserAgentsBuilder::new()
|
7 |
.cache(false)
|
8 |
.dir("/tmp")
|
|
|
16 |
.set_mozilla(),
|
17 |
)
|
18 |
.build()
|
19 |
+
});
|
20 |
+
|
21 |
+
/// A function to generate random user agent to improve privacy of the user.
|
22 |
+
///
|
23 |
+
/// # Returns
|
24 |
+
///
|
25 |
+
/// A randomly generated user agent string.
|
26 |
+
pub fn random_user_agent() -> String {
|
27 |
+
USER_AGENTS.random().to_string()
|
28 |
}
|