diff --git a/cli/http_util.rs b/cli/http_util.rs index 12e70e3e74..2278afc8d9 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -117,6 +117,15 @@ pub fn fetch_once( let mut headers_: HashMap = HashMap::new(); let headers = response.headers(); + + if let Some(warning) = headers.get("X-Deno-Warning") { + eprintln!( + "{} {}", + crate::colors::yellow("Warning".to_string()), + warning.to_str().unwrap() + ); + } + for key in headers.keys() { let key_str = key.to_string(); let values = headers.get_all(key); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 7ad7781de7..4897422b9d 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -12,6 +12,28 @@ use std::io::BufRead; use std::process::Command; use tempfile::TempDir; +#[test] +fn x_deno_warning() { + let g = util::http_server(); + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("run") + .arg("--reload") + .arg("http://127.0.0.1:4545/cli/tests/x_deno_warning.js") + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let stdout_str = std::str::from_utf8(&output.stdout).unwrap().trim(); + let stderr_str = std::str::from_utf8(&output.stderr).unwrap().trim(); + assert_eq!("testing x-deno-warning header", stdout_str); + assert!(deno::colors::strip_ansi_codes(stderr_str).contains("Warning foobar")); + drop(g); +} + #[test] fn no_color() { let output = util::deno_cmd() diff --git a/cli/tests/x_deno_warning.js b/cli/tests/x_deno_warning.js new file mode 100644 index 0000000000..34b950566f --- /dev/null +++ b/cli/tests/x_deno_warning.js @@ -0,0 +1 @@ +console.log("testing x-deno-warning header"); diff --git a/cli/tests/x_deno_warning.js.header b/cli/tests/x_deno_warning.js.header new file mode 100644 index 0000000000..9a8ba0190c --- /dev/null +++ b/cli/tests/x_deno_warning.js.header @@ -0,0 +1,2 @@ +Content-Type: application/javascript +X-Deno-Warning: foobar \ No newline at end of file