Skip to content

Commit c671c3b

Browse files
ling0xSytten
andauthored
feat: add disable https first features (#277)
* feat: add disable https first features * Add integration test * Try fixing disable https first * Revert previous change Doesnt seem to work * Refactor the arguments to combine them automatically * Display browser version * Print url for debug * Debug chrome policies * Try HttpsFirstBalancedMode * Disable test for now --------- Co-authored-by: ling0x <[email protected]> Co-authored-by: Emile Fugulin <[email protected]>
1 parent 31fee26 commit c671c3b

6 files changed

Lines changed: 652 additions & 464 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Use a struct `Arg` for arguments to combine flags automatically
13+
1014
### Added
1115

1216
- Add `add_init_script` to `Page` for scripts before navigation

src/browser/argument.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
use std::collections::HashMap;
2+
use std::fmt;
3+
4+
pub struct ArgsBuilder(HashMap<String, Vec<String>>);
5+
6+
impl ArgsBuilder {
7+
pub fn new() -> Self {
8+
Self(HashMap::new())
9+
}
10+
11+
pub fn has(&self, key: &str) -> bool {
12+
self.0.contains_key(key)
13+
}
14+
15+
pub fn arg<T: Into<Arg>>(&mut self, arg: T) -> &mut Self {
16+
let arg = arg.into();
17+
if let Some(values) = self.0.get_mut(&arg.key) {
18+
values.extend(arg.values);
19+
} else {
20+
self.0.insert(arg.key, arg.values);
21+
}
22+
self
23+
}
24+
25+
pub fn args<T: Into<Arg>>(&mut self, args: impl IntoIterator<Item = T>) -> &mut Self {
26+
for arg in args {
27+
self.arg(arg);
28+
}
29+
self
30+
}
31+
32+
pub fn into_iter(self) -> impl Iterator<Item = String> {
33+
self.0.into_iter().map(|(key, values)| {
34+
if values.is_empty() {
35+
format!("--{}", key)
36+
} else {
37+
format!("--{}={}", key, values.join(","))
38+
}
39+
})
40+
}
41+
}
42+
43+
#[derive(Debug, Clone)]
44+
pub struct Arg {
45+
key: String,
46+
values: Vec<String>,
47+
}
48+
49+
impl Arg {
50+
pub fn key(key: impl AsRef<str>) -> Self {
51+
Self {
52+
key: key.as_ref().to_string(),
53+
values: Vec::new(),
54+
}
55+
}
56+
57+
pub fn value(key: impl AsRef<str>, value: impl fmt::Display) -> Self {
58+
Self {
59+
key: key.as_ref().to_string(),
60+
values: vec![value.to_string()],
61+
}
62+
}
63+
64+
pub fn values(
65+
key: impl AsRef<str>,
66+
values: impl IntoIterator<Item = impl fmt::Display>,
67+
) -> Self {
68+
Self {
69+
key: key.as_ref().to_string(),
70+
values: values.into_iter().map(|v| v.to_string()).collect(),
71+
}
72+
}
73+
}
74+
75+
impl From<(&str, &str)> for Arg {
76+
fn from((key, value): (&str, &str)) -> Self {
77+
Self {
78+
key: key.to_string(),
79+
values: vec![value.to_string()],
80+
}
81+
}
82+
}
83+
84+
impl From<(&str, &[&str])> for Arg {
85+
fn from((key, values): (&str, &[&str])) -> Self {
86+
Self {
87+
key: key.to_string(),
88+
values: values.iter().map(|v| v.to_string()).collect(),
89+
}
90+
}
91+
}
92+
93+
impl From<&str> for Arg {
94+
fn from(value: &str) -> Self {
95+
Self {
96+
key: value.to_string(),
97+
values: Vec::new(),
98+
}
99+
}
100+
}
101+
102+
impl From<String> for Arg {
103+
fn from(value: String) -> Self {
104+
Self {
105+
key: value,
106+
values: Vec::new(),
107+
}
108+
}
109+
}
110+
111+
impl From<ArgConst> for Arg {
112+
fn from(arg: ArgConst) -> Self {
113+
Self {
114+
key: arg.key.to_string(),
115+
values: arg.values.iter().map(|v| v.to_string()).collect(),
116+
}
117+
}
118+
}
119+
120+
#[derive(Debug, Clone)]
121+
pub struct ArgConst {
122+
key: &'static str,
123+
values: &'static [&'static str],
124+
}
125+
126+
impl ArgConst {
127+
pub const fn key(key: &'static str) -> Self {
128+
Self { key, values: &[] }
129+
}
130+
131+
pub const fn values(key: &'static str, values: &'static [&'static str]) -> Self {
132+
Self { key, values }
133+
}
134+
}

0 commit comments

Comments
 (0)