Skip to content

Commit 54b8347

Browse files
committed
feat(ext/fetch): Parse vsock proxy from env var
1 parent b538c98 commit 54b8347

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ext/fetch/proxy.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ impl Target {
214214
path: decoded.into(),
215215
});
216216
}
217+
// vsock:<cid>:<port> is valid RFC3986 but not as an http::Uri
218+
#[cfg(any(target_os = "linux", target_os = "macos"))]
219+
if let Some(cid_port) = val.strip_prefix("vsock:") {
220+
let (left, right) = cid_port.split_once(":")?;
221+
let cid = left.parse::<u32>().ok()?;
222+
let port = right.parse::<u32>().ok()?;
223+
return Some(Target::Vsock { cid, port });
224+
}
217225

218226
let uri = val.parse::<Uri>().ok()?;
219227

@@ -920,6 +928,16 @@ fn test_proxy_parse_from_env() {
920928
}
921929
_ => panic!("bad target"),
922930
}
931+
932+
// vsock
933+
#[cfg(any(target_os = "linux", target_os = "macos"))]
934+
match parse("vsock:1234:5678") {
935+
Target::Vsock { cid, port } => {
936+
assert_eq!(cid, 1234);
937+
assert_eq!(port, 5678);
938+
}
939+
_ => panic!("bad target"),
940+
}
923941
}
924942

925943
#[test]

0 commit comments

Comments
 (0)