diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-08-15 16:30:33 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-15 22:30:33 +0000 |
commit | 71d2f4cb97b6cc85cf58c632ecde05cc262ff44f (patch) | |
tree | 54f20ea902584201fa2fc69f0aa8776f54ecc3a1 /cli | |
parent | 4380a09a0598c73aa434e2f0f3a34555e0bd55cb (diff) |
fix(runtime): use host header for inspector websocket URL (#20171)
If a `host` header is specified, use that for the generated websocket
URLs.
Fixes #20087
Diffstat (limited to 'cli')
-rw-r--r-- | cli/tests/integration/inspector_tests.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/cli/tests/integration/inspector_tests.rs b/cli/tests/integration/inspector_tests.rs index 6b2deb0bf..79422ee5a 100644 --- a/cli/tests/integration/inspector_tests.rs +++ b/cli/tests/integration/inspector_tests.rs @@ -9,6 +9,8 @@ use deno_runtime::deno_fetch::reqwest; use fastwebsockets::FragmentCollector; use fastwebsockets::Frame; use fastwebsockets::WebSocket; +use http::header::HOST; +use hyper::header::HeaderValue; use hyper::upgrade::Upgraded; use hyper::Body; use hyper::Request; @@ -704,14 +706,34 @@ async fn inspector_json() { 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: Vec<deno_core::serde_json::Value> = - serde_json::from_str(&resp.text().await.unwrap()).unwrap(); - let matching_endpoint = endpoint_list - .iter() - .find(|e| e["webSocketDebuggerUrl"] == ws_url.as_str()); - assert!(matching_endpoint.is_some()); + let client = reqwest::Client::new(); + + // Ensure that the webSocketDebuggerUrl matches the host header + for (host, expected) in [ + (None, ws_url.as_str()), + (Some("some.random.host"), "ws://some.random.host/"), + (Some("some.random.host:1234"), "ws://some.random.host:1234/"), + (Some("[::1]:1234"), "ws://[::1]:1234/"), + ] { + let mut req = reqwest::Request::new(reqwest::Method::GET, url.clone()); + if let Some(host) = host { + req + .headers_mut() + .insert(HOST, HeaderValue::from_static(host)); + } + let resp = client.execute(req).await.unwrap(); + assert_eq!(resp.status(), reqwest::StatusCode::OK); + let endpoint_list: Vec<deno_core::serde_json::Value> = + serde_json::from_str(&resp.text().await.unwrap()).unwrap(); + let matching_endpoint = endpoint_list.iter().find(|e| { + e["webSocketDebuggerUrl"] + .as_str() + .unwrap() + .contains(expected) + }); + assert!(matching_endpoint.is_some()); + } + child.kill().unwrap(); } |