Skip to content

Commit 7398ca5

Browse files
committed
Fix xhttp clash config
1 parent a110b21 commit 7398ca5

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/xray_op/clash.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub enum ClashProxy {
4343
reality_opts: RealityOpts,
4444
#[serde(rename = "grpc-opts", skip_serializing_if = "Option::is_none")]
4545
grpc_opts: Option<GrpcOpts>,
46+
#[serde(rename = "http-opts", skip_serializing_if = "Option::is_none")]
47+
http_opts: Option<XHttpOpts>,
4648
#[serde(rename = "client-fingerprint")]
4749
client_fingerprint: String,
4850
#[serde(skip_serializing_if = "Option::is_none")]
@@ -61,6 +63,15 @@ pub struct HttpOpts {
6163
}
6264

6365
#[derive(Serialize)]
66+
pub struct XHttpOpts {
67+
method: &'static str,
68+
path: Vec<String>,
69+
#[serde(rename = "ip-version")]
70+
ip_version: &'static str,
71+
host: String,
72+
}
73+
74+
#[derive(Serialize, Default)]
6475
pub struct HttpHeaders {
6576
connection: Vec<&'static str>,
6677
}
@@ -133,21 +144,37 @@ pub fn generate_proxy_config(
133144
Tag::VlessGrpcReality | Tag::VlessTcpReality | Tag::VlessXhttpReality => {
134145
let reality = stream.reality_settings.as_ref()?;
135146

136-
let (network, grpc_opts, flow) = if let Some(grpc) = &stream.grpc_settings {
147+
let (network, grpc_opts, flow, http_opts) = if let Some(grpc) = &stream.grpc_settings {
137148
(
138149
"grpc".to_string(),
139150
Some(GrpcOpts {
140151
grpc_service_name: grpc.service_name.clone(),
141152
ip_version: "dual",
142153
}),
143154
None,
155+
None,
144156
)
145-
} else {
157+
} else if let Some(xhttp) = &stream.xhttp_settings {
158+
(
159+
"http".to_string(),
160+
None,
161+
None,
162+
Some(XHttpOpts {
163+
method: "GET",
164+
path: vec![xhttp.path.clone()],
165+
ip_version: "dual",
166+
host: reality.server_names.get(0).cloned().unwrap_or_default(),
167+
}),
168+
)
169+
} else if stream.tcp_settings.is_some() {
146170
(
147171
"tcp".to_string(),
148172
None,
149173
Some("xtls-rprx-vision".to_string()),
174+
None,
150175
)
176+
} else {
177+
return None;
151178
};
152179

153180
let name = format!("{} [{}]", label, inbound.tag);
@@ -158,18 +185,24 @@ pub fn generate_proxy_config(
158185
port,
159186
uuid: conn_id.to_string(),
160187
udp: true,
188+
161189
tls: true,
162190
network,
163191
servername: reality.server_names.get(0).cloned().unwrap_or_default(),
192+
164193
client_fingerprint: "chrome".to_string(),
194+
165195
reality_opts: RealityOpts {
166196
public_key: reality.public_key.clone(),
167197
short_id: reality.short_ids.get(0).cloned().unwrap_or_default(),
168198
},
199+
169200
grpc_opts,
201+
http_opts,
170202
flow,
171203
})
172204
}
205+
173206
_ => return None,
174207
};
175208

0 commit comments

Comments
 (0)