mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
fix(inspector): add back list endpoint (#8894)
This commit adds back "/json/list" endpoint to inspector server which was erroneously removed during server rewrite. Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
0a509152d1
commit
1a2e7741c3
4 changed files with 235 additions and 15 deletions
155
Cargo.lock
generated
155
Cargo.lock
generated
|
@ -307,6 +307,22 @@ dependencies = [
|
||||||
"proc-macro-hack",
|
"proc-macro-hack",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62"
|
||||||
|
dependencies = [
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation-sys"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpuid-bool"
|
name = "cpuid-bool"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
@ -432,6 +448,7 @@ dependencies = [
|
||||||
"os_pipe",
|
"os_pipe",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"regex",
|
"regex",
|
||||||
|
"reqwest",
|
||||||
"ring",
|
"ring",
|
||||||
"rustyline",
|
"rustyline",
|
||||||
"rustyline-derive",
|
"rustyline-derive",
|
||||||
|
@ -789,6 +806,21 @@ version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foreign-types"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||||
|
dependencies = [
|
||||||
|
"foreign-types-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "foreign-types-shared"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "form_urlencoded"
|
name = "form_urlencoded"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
@ -1132,6 +1164,19 @@ dependencies = [
|
||||||
"webpki",
|
"webpki",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper-tls"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed"
|
||||||
|
dependencies = [
|
||||||
|
"bytes 0.5.6",
|
||||||
|
"hyper",
|
||||||
|
"native-tls",
|
||||||
|
"tokio 0.2.22",
|
||||||
|
"tokio-tls",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ident_case"
|
name = "ident_case"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -1504,6 +1549,24 @@ dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "native-tls"
|
||||||
|
version = "0.2.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"openssl",
|
||||||
|
"openssl-probe",
|
||||||
|
"openssl-sys",
|
||||||
|
"schannel",
|
||||||
|
"security-framework",
|
||||||
|
"security-framework-sys",
|
||||||
|
"tempfile",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "net2"
|
name = "net2"
|
||||||
version = "0.2.35"
|
version = "0.2.35"
|
||||||
|
@ -1626,6 +1689,39 @@ version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl"
|
||||||
|
version = "0.10.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"foreign-types",
|
||||||
|
"lazy_static",
|
||||||
|
"libc",
|
||||||
|
"openssl-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-probe"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-sys"
|
||||||
|
version = "0.9.60"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ordered-float"
|
name = "ordered-float"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
@ -1798,6 +1894,12 @@ version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pmutil"
|
name = "pmutil"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
|
@ -2021,19 +2123,23 @@ dependencies = [
|
||||||
"http-body",
|
"http-body",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-rustls",
|
"hyper-rustls",
|
||||||
|
"hyper-tls",
|
||||||
"ipnet",
|
"ipnet",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"mime",
|
"mime",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
|
"native-tls",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite 0.1.7",
|
"pin-project-lite 0.1.7",
|
||||||
"rustls",
|
"rustls",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"tokio 0.2.22",
|
"tokio 0.2.22",
|
||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
|
"tokio-tls",
|
||||||
"url",
|
"url",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
|
@ -2144,6 +2250,16 @@ dependencies = [
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "schannel"
|
||||||
|
version = "0.1.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scoped-tls"
|
name = "scoped-tls"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
@ -2166,6 +2282,29 @@ dependencies = [
|
||||||
"untrusted",
|
"untrusted",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "security-framework"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"core-foundation",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
"security-framework-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "security-framework-sys"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b"
|
||||||
|
dependencies = [
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
@ -2901,6 +3040,16 @@ dependencies = [
|
||||||
"tokio 0.2.22",
|
"tokio 0.2.22",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-tls"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343"
|
||||||
|
dependencies = [
|
||||||
|
"native-tls",
|
||||||
|
"tokio 0.2.22",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-tungstenite"
|
name = "tokio-tungstenite"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
@ -3105,6 +3254,12 @@ dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vcpkg"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
|
|
@ -86,6 +86,7 @@ os_pipe = "0.9.2"
|
||||||
test_util = { path = "../test_util" }
|
test_util = { path = "../test_util" }
|
||||||
tokio-tungstenite = "0.11.0"
|
tokio-tungstenite = "0.11.0"
|
||||||
tower-test = "0.3.0"
|
tower-test = "0.3.0"
|
||||||
|
reqwest = {version = "0.10.8", features = ["json"]}
|
||||||
|
|
||||||
[target.'cfg(unix)'.dev-dependencies]
|
[target.'cfg(unix)'.dev-dependencies]
|
||||||
exec = "0.3.1" # Used in test_raw_tty
|
exec = "0.3.1" # Used in test_raw_tty
|
||||||
|
|
|
@ -4345,6 +4345,66 @@ async fn inspector_runtime_evaluate_does_not_crash() {
|
||||||
child.wait().unwrap();
|
child.wait().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn inspector_json() {
|
||||||
|
let script = util::tests_path().join("inspector1.js");
|
||||||
|
let mut child = util::deno_cmd()
|
||||||
|
.arg("run")
|
||||||
|
.arg(inspect_flag_with_unique_port("--inspect"))
|
||||||
|
.arg(script)
|
||||||
|
.stderr(std::process::Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let stderr = child.stderr.as_mut().unwrap();
|
||||||
|
let mut stderr_lines =
|
||||||
|
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());
|
||||||
|
let ws_url = extract_ws_url_from_stderr(&mut stderr_lines);
|
||||||
|
let mut url = ws_url.clone();
|
||||||
|
let _ = url.set_scheme("http");
|
||||||
|
url.set_path("/json");
|
||||||
|
let resp = reqwest::get(url).await.unwrap();
|
||||||
|
assert_eq!(resp.status(), reqwest::StatusCode::OK);
|
||||||
|
let endpoint_list = resp
|
||||||
|
.json::<Vec<deno_core::serde_json::Value>>()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let matching_endpoint = endpoint_list
|
||||||
|
.iter()
|
||||||
|
.find(|e| e["webSocketDebuggerUrl"] == ws_url.as_str());
|
||||||
|
assert!(matching_endpoint.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn inspector_json_list() {
|
||||||
|
let script = util::tests_path().join("inspector1.js");
|
||||||
|
let mut child = util::deno_cmd()
|
||||||
|
.arg("run")
|
||||||
|
.arg(inspect_flag_with_unique_port("--inspect"))
|
||||||
|
.arg(script)
|
||||||
|
.stderr(std::process::Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let stderr = child.stderr.as_mut().unwrap();
|
||||||
|
let mut stderr_lines =
|
||||||
|
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());
|
||||||
|
let ws_url = extract_ws_url_from_stderr(&mut stderr_lines);
|
||||||
|
let mut url = ws_url.clone();
|
||||||
|
let _ = url.set_scheme("http");
|
||||||
|
url.set_path("/json/list");
|
||||||
|
let resp = reqwest::get(url).await.unwrap();
|
||||||
|
assert_eq!(resp.status(), reqwest::StatusCode::OK);
|
||||||
|
let endpoint_list = resp
|
||||||
|
.json::<Vec<deno_core::serde_json::Value>>()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let matching_endpoint = endpoint_list
|
||||||
|
.iter()
|
||||||
|
.find(|e| e["webSocketDebuggerUrl"] == ws_url.as_str());
|
||||||
|
assert!(matching_endpoint.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn websocket() {
|
fn websocket() {
|
||||||
let _g = util::http_server();
|
let _g = util::http_server();
|
||||||
|
|
|
@ -182,20 +182,21 @@ fn handle_ws_request(
|
||||||
.status(http::StatusCode::BAD_REQUEST)
|
.status(http::StatusCode::BAD_REQUEST)
|
||||||
.body("Not a valid Websocket Request".into()),
|
.body("Not a valid Websocket Request".into()),
|
||||||
});
|
});
|
||||||
tokio::task::spawn_local(async move {
|
if resp.is_ok() {
|
||||||
let upgraded = body.on_upgrade().await.unwrap();
|
tokio::task::spawn_local(async move {
|
||||||
let websocket = tokio_tungstenite::WebSocketStream::from_raw_socket(
|
let upgraded = body.on_upgrade().await.unwrap();
|
||||||
upgraded,
|
let websocket = tokio_tungstenite::WebSocketStream::from_raw_socket(
|
||||||
tungstenite::protocol::Role::Server,
|
upgraded,
|
||||||
None,
|
tungstenite::protocol::Role::Server,
|
||||||
)
|
None,
|
||||||
.await;
|
)
|
||||||
let (proxy, pump) = create_websocket_proxy(websocket);
|
.await;
|
||||||
|
let (proxy, pump) = create_websocket_proxy(websocket);
|
||||||
let _ = new_websocket_tx.unbounded_send(proxy);
|
|
||||||
pump.await;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
let _ = new_websocket_tx.unbounded_send(proxy);
|
||||||
|
pump.await;
|
||||||
|
});
|
||||||
|
}
|
||||||
resp
|
resp
|
||||||
} else {
|
} else {
|
||||||
http::Response::builder()
|
http::Response::builder()
|
||||||
|
@ -275,11 +276,14 @@ async fn server(
|
||||||
(&http::Method::GET, path) if path.starts_with("/ws/") => {
|
(&http::Method::GET, path) if path.starts_with("/ws/") => {
|
||||||
handle_ws_request(req, inspector_map.clone())
|
handle_ws_request(req, inspector_map.clone())
|
||||||
}
|
}
|
||||||
|
(&http::Method::GET, "/json/version") => {
|
||||||
|
handle_json_version_request(json_version_response.clone())
|
||||||
|
}
|
||||||
(&http::Method::GET, "/json") => {
|
(&http::Method::GET, "/json") => {
|
||||||
handle_json_request(inspector_map.clone())
|
handle_json_request(inspector_map.clone())
|
||||||
}
|
}
|
||||||
(&http::Method::GET, "/json/version") => {
|
(&http::Method::GET, "/json/list") => {
|
||||||
handle_json_version_request(json_version_response.clone())
|
handle_json_request(inspector_map.clone())
|
||||||
}
|
}
|
||||||
_ => http::Response::builder()
|
_ => http::Response::builder()
|
||||||
.status(http::StatusCode::NOT_FOUND)
|
.status(http::StatusCode::NOT_FOUND)
|
||||||
|
|
Loading…
Reference in a new issue