From 24881769892da3d8400c7c6821ef225b268ad88e Mon Sep 17 00:00:00 2001 From: Till H <6740568+Till--H@users.noreply.github.com> Date: Sat, 6 Feb 2021 11:16:07 +0100 Subject: [PATCH] Add support for HEAD - Support HEAD requests --- src/cli.rs | 3 +++ tests/cli.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index b830d2f3..cad3dc53 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -113,6 +113,7 @@ impl Cli { #[derive(Debug, Clone, Copy)] pub enum Method { GET, + HEAD, POST, PUT, PATCH, @@ -124,6 +125,7 @@ impl FromStr for Method { fn from_str(s: &str) -> Result { match s.to_ascii_uppercase().as_str() { "GET" => Ok(Method::GET), + "HEAD" => Ok(Method::HEAD), "POST" => Ok(Method::POST), "PUT" => Ok(Method::PUT), "PATCH" => Ok(Method::PATCH), @@ -142,6 +144,7 @@ impl From for reqwest::Method { fn from(method: Method) -> Self { match method { Method::GET => reqwest::Method::GET, + Method::HEAD => reqwest::Method::HEAD, Method::POST => reqwest::Method::POST, Method::PUT => reqwest::Method::PUT, Method::PATCH => reqwest::Method::PATCH, diff --git a/tests/cli.rs b/tests/cli.rs index f6400ae3..253cde8f 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -30,3 +30,48 @@ fn basic_post() -> Result<(), Box> { Ok(()) } + +#[test] +fn basic_get() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("ht")?; + cmd.arg("-v") + .arg("--offline") + .arg("--ignore-stdin") + .arg("--pretty=format") + .arg("get") + .arg("httpbin.org/get"); + + cmd.assert().stdout(indoc! {r#" + GET /get HTTP/1.1 + accept: */* + accept-encoding: gzip, deflate + connection: keep-alive + host: httpbin.org + + "#}); + + Ok(()) +} + +#[test] +fn basic_head() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("ht")?; + cmd.arg("-v") + .arg("--offline") + .arg("--ignore-stdin") + .arg("--pretty=format") + .arg("head") + .arg("httpbin.org/get"); + + cmd.assert().stdout(indoc! {r#" + HEAD /get HTTP/1.1 + accept: */* + accept-encoding: gzip, deflate + connection: keep-alive + host: httpbin.org + + "#}); + + Ok(()) +} +