mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
Add support for X-Deno-Warning header (#5161)
This commit is contained in:
parent
d5dd5ae87d
commit
eb505f8afc
4 changed files with 34 additions and 0 deletions
|
@ -117,6 +117,15 @@ pub fn fetch_once(
|
|||
|
||||
let mut headers_: HashMap<String, String> = 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);
|
||||
|
|
|
@ -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()
|
||||
|
|
1
cli/tests/x_deno_warning.js
Normal file
1
cli/tests/x_deno_warning.js
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("testing x-deno-warning header");
|
2
cli/tests/x_deno_warning.js.header
Normal file
2
cli/tests/x_deno_warning.js.header
Normal file
|
@ -0,0 +1,2 @@
|
|||
Content-Type: application/javascript
|
||||
X-Deno-Warning: foobar
|
Loading…
Reference in a new issue