Skip to content

Commit

Permalink
Merge pull request #16 from Till--H/feature/head
Browse files Browse the repository at this point in the history
Add support for HEAD requests
  • Loading branch information
ducaale authored Feb 6, 2021
2 parents 23014db + 2488176 commit c049e25
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl Cli {
#[derive(Debug, Clone, Copy)]
pub enum Method {
GET,
HEAD,
POST,
PUT,
PATCH,
Expand All @@ -132,6 +133,7 @@ impl FromStr for Method {
fn from_str(s: &str) -> Result<Method> {
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),
Expand All @@ -150,6 +152,7 @@ impl From<Method> 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,
Expand Down
45 changes: 45 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,48 @@ fn basic_post() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[test]
fn basic_get() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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(())
}

0 comments on commit c049e25

Please sign in to comment.