1
0
Fork 0
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:
Ryan Dahl 2020-05-09 12:43:24 -04:00 committed by GitHub
parent d5dd5ae87d
commit eb505f8afc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

View file

@ -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);

View file

@ -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()

View file

@ -0,0 +1 @@
console.log("testing x-deno-warning header");

View file

@ -0,0 +1,2 @@
Content-Type: application/javascript
X-Deno-Warning: foobar