diff --git a/hitt-cli/src/printing/mod.rs b/hitt-cli/src/printing/mod.rs index 68fa129..6bf7ea6 100644 --- a/hitt-cli/src/printing/mod.rs +++ b/hitt-cli/src/printing/mod.rs @@ -25,6 +25,7 @@ pub const TEXT_RESET: &str = "\x1B[39m"; pub(crate) fn print_response(response: HittResponse, args: &CliArguments) { print_status( + &response.http_version, &response.method, &response.url, response.status_code.as_u16(), diff --git a/hitt-cli/src/printing/status.rs b/hitt-cli/src/printing/status.rs index eb5adfb..34ea766 100644 --- a/hitt-cli/src/printing/status.rs +++ b/hitt-cli/src/printing/status.rs @@ -1,12 +1,22 @@ +use hitt_parser::http; + use crate::printing::{STYLE_BOLD, STYLE_RESET, TEXT_GREEN, TEXT_RED, TEXT_RESET}; #[inline] -pub(crate) fn print_status(method: &str, url: &str, status_code: u16) { +pub(crate) fn print_status( + http_version: &http::version::Version, + method: &str, + url: &str, + status_code: u16, +) { let text_color = if status_code < 400 { TEXT_GREEN } else { TEXT_RED }; - println!("{STYLE_BOLD}{text_color}{method} {url} {status_code}{TEXT_RESET}{STYLE_RESET}"); + println!( + "{STYLE_BOLD}{text_color}{:?} {method} {url} {status_code}{TEXT_RESET}{STYLE_RESET}", + http_version + ); } diff --git a/hitt-parser/src/lib.rs b/hitt-parser/src/lib.rs index 8f29a61..d447819 100644 --- a/hitt-parser/src/lib.rs +++ b/hitt-parser/src/lib.rs @@ -1,5 +1,7 @@ use std::str::FromStr; +pub use http; + #[derive(Debug)] pub enum RequestParseError { InvalidHttpMethod(http::method::InvalidMethod), diff --git a/hitt-request/src/lib.rs b/hitt-request/src/lib.rs index 1d7d064..a4a2c43 100644 --- a/hitt-request/src/lib.rs +++ b/hitt-request/src/lib.rs @@ -1,4 +1,4 @@ -use hitt_parser::HittRequest; +use hitt_parser::{http, HittRequest}; pub struct HittResponse { pub url: String, @@ -6,6 +6,7 @@ pub struct HittResponse { pub status_code: reqwest::StatusCode, pub headers: reqwest::header::HeaderMap, pub body: String, + pub http_version: http::version::Version, } pub async fn send_request( @@ -27,6 +28,8 @@ pub async fn send_request( let status_code = res.status(); let headers = res.headers().to_owned(); + let http_version = res.version(); + let body = res.text().await.unwrap_or_default(); Ok(HittResponse { @@ -35,5 +38,6 @@ pub async fn send_request( status_code, headers, body, + http_version, }) }