Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1e718c7

Browse files
committedFeb 21, 2024·
feat(importer): add socks5, http translation
1 parent 14cd4f0 commit 1e718c7

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed
 

‎src/config/importer/clash.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ fn with_net(mut net: Net, target_net: Option<Net>) -> Net {
123123

124124
impl Clash {
125125
fn proxy_to_net(&self, p: Proxy, target_net: Option<Net>) -> Result<Net> {
126-
let net = match p.proxy_type.as_ref() {
126+
// TODO: http and socks5 has limited support
127+
let net: Net = match p.proxy_type.as_ref() {
127128
"ss" => {
128129
#[derive(Debug, Deserialize)]
129130
#[serde(rename_all = "kebab-case")]
@@ -193,6 +194,7 @@ impl Clash {
193194
// udp is ignored
194195
// udp: Option<bool>,
195196
sni: Option<String>,
197+
#[serde(rename = "skip-cert-verify")]
196198
skip_cert_verify: Option<bool>,
197199
}
198200
let params: Param = serde_json::from_value(p.opt)?;
@@ -209,6 +211,40 @@ impl Clash {
209211
target_net,
210212
)
211213
}
214+
"http" => {
215+
#[derive(Debug, Deserialize)]
216+
struct Param {
217+
server: String,
218+
port: u16,
219+
}
220+
let params: Param = serde_json::from_value(p.opt)?;
221+
with_net(
222+
Net::new(
223+
"http",
224+
json!({
225+
"server": format!("{}:{}", params.server, params.port),
226+
}),
227+
),
228+
target_net,
229+
)
230+
}
231+
"socks5" => {
232+
#[derive(Debug, Deserialize)]
233+
struct Param {
234+
server: String,
235+
port: u16,
236+
}
237+
let params: Param = serde_json::from_value(p.opt)?;
238+
with_net(
239+
Net::new(
240+
"socks5",
241+
json!({
242+
"server": format!("{}:{}", params.server, params.port),
243+
}),
244+
),
245+
target_net,
246+
)
247+
}
212248
_ => return Err(anyhow!("Unsupported proxy type: {}", p.proxy_type)),
213249
};
214250
Ok(net)

0 commit comments

Comments
 (0)
Please sign in to comment.