-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Eval EXEC <[email protected]>
- Loading branch information
Showing
7 changed files
with
48 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
pub(crate) fn check_proxy_url(proxy_url: &str) -> Result<(), String> { | ||
let parsed_url = url::Url::parse(proxy_url).map_err(|e| e.to_string())?; | ||
if parsed_url.host_str().is_none() { | ||
return Err( format!("missing host in proxy url: {}", proxy_url) ); | ||
} | ||
let scheme = parsed_url.scheme(); | ||
if scheme.ne("socks5") { | ||
return Err(format!("CKB doesn't support proxy scheme: {}", scheme)); | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn parse_socks5_url() { | ||
let result = url::Url::parse("socks5://username:password@localhost:1080"); | ||
assert!(result.is_ok()); | ||
let parsed_url = result.unwrap(); | ||
dbg!(&parsed_url); | ||
assert_eq!(parsed_url.scheme(), "socks5"); | ||
// username | ||
assert_eq!(parsed_url.username(), "username"); | ||
// password | ||
assert_eq!(parsed_url.password(), Some("password")); | ||
// host | ||
assert_eq!(parsed_url.host_str(), Some("localhost")); | ||
// port | ||
assert_eq!(parsed_url.port(), Some(1080)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,7 @@ pub struct Config { | |
#[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
pub struct ProxyConfig { | ||
pub enable: bool, | ||
// like: socks5://username:[email protected]:1080 | ||
pub proxy_url: String, | ||
} | ||
|
||
|