Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uuid = { version = "^1.0", features = ["v4"] }
chrono = { version = "^0.4", features = ["serde"] }
colored = "^3.0"
indicatif = "^0.18"
windows-sys = { version = "0.61.0", features = ["Win32_Foundation", "Win32_System_Console"] }
windows-sys = { version = "0.61.1", features = ["Win32_Foundation", "Win32_System_Console"] }
anyhow = "^1.0"
toml = "^0.9"
url = "^2.4"
Expand Down
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ default_interval = 3
# Display settings
show_headers_by_default = false
show_full_body_by_default = false
body_preview_length = 80
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl WebhookClient {
}

pub async fn get_requests(&self, token: &str, count: u32) -> Result<Vec<WebhookRequest>> {
let url = format!("{}/{}/log/{}", self.base_url, token, count);
let url = Config::join_url_segments(&self.base_url, &[token, "log", &count.to_string()]);

let response = self
.client
Expand Down
37 changes: 23 additions & 14 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use uuid::Uuid;
use crate::client::WebhookClient;
use crate::config::Config;
use crate::display::{
print_full_request_body, print_request_body, print_request_details, print_request_headers,
print_request_summary,
print_full_request_body, print_request_details, print_request_headers, print_request_summary,
};

pub async fn generate_token(config: &Config) -> Result<()> {
let token = Uuid::new_v4();
let webhook_url = format!("{}/{}", config.get_base_url(), token);
let webhook_url = Config::join_url_segments(config.get_base_url(), &[&token.to_string()]);

println!("{}", "New webhook token generated!".bright_green().bold());
println!();
Expand All @@ -37,8 +36,10 @@ pub async fn generate_token(config: &Config) -> Result<()> {
Ok(())
}

#[allow(clippy::too_many_arguments)]
pub async fn monitor_requests(
client: &WebhookClient,
config: &Config,
token: &str,
initial_count: u32,
interval: u64,
Expand Down Expand Up @@ -67,7 +68,7 @@ pub async fn monitor_requests(
.into_iter()
.filter(|req| {
method_filter.is_none_or(|method| {
req.message_object.method.to_lowercase() == method.to_lowercase()
req.message_object.method.eq_ignore_ascii_case(method)
})
})
.collect();
Expand All @@ -85,8 +86,13 @@ pub async fn monitor_requests(
"Found".bright_blue(),
filtered_requests.len()
);
for request in &filtered_requests {
print_request_summary(request);
// Reverse the order so latest requests appear at the end
for request in filtered_requests.iter().rev() {
print_request_summary(
request,
!full_body,
config.get_body_preview_length(),
); // Don't show body preview in full body mode
if show_headers {
print_request_headers(request);
}
Expand All @@ -106,14 +112,16 @@ pub async fn monitor_requests(
.collect();
for request in &new_requests {
println!("{}", "NEW REQUEST".bright_green().bold());
print_request_summary(request);
print_request_summary(
request,
!full_body,
config.get_body_preview_length(),
); // Don't show body preview in full body mode
if show_headers {
print_request_headers(request);
}
if full_body {
print_full_request_body(request);
} else {
print_request_body(request);
}
println!("{}", "─".repeat(80).bright_black());
last_seen_ids.insert(request.id.clone());
Expand All @@ -131,6 +139,7 @@ pub async fn monitor_requests(

pub async fn show_logs(
client: &WebhookClient,
config: &Config,
token: &str,
count: u32,
method_filter: Option<&str>,
Expand All @@ -150,9 +159,8 @@ pub async fn show_logs(
let filtered_requests: Vec<_> = requests
.into_iter()
.filter(|req| {
method_filter.is_none_or(|method| {
req.message_object.method.to_lowercase() == method.to_lowercase()
})
method_filter
.is_none_or(|method| req.message_object.method.eq_ignore_ascii_case(method))
})
.collect();

Expand All @@ -176,8 +184,9 @@ pub async fn show_logs(
}

println!("{}", "─".repeat(80).bright_black());
for request in &filtered_requests {
print_request_summary(request);
// Reverse the order so latest requests appear at the end
for request in filtered_requests.iter().rev() {
print_request_summary(request, !full_body, config.get_body_preview_length()); // Don't show body preview in full body mode
Comment on lines +187 to +189
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Format inconsistency: reflow to multi-line.

The print_request_summary call here uses single-line formatting, whereas lines 89-95 and 115-119 use multi-line formatting with each argument on a separate line. This inconsistency may fail rustfmt checks.

Apply this diff to match the formatting style used elsewhere in the file:

     // Reverse the order so latest requests appear at the end
     for request in filtered_requests.iter().rev() {
-        print_request_summary(request, !full_body, config.get_body_preview_length()); // Don't show body preview in full body mode
+        print_request_summary(
+            request,
+            !full_body,
+            config.get_body_preview_length(),
+        ); // Don't show body preview in full body mode
         if show_headers {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Reverse the order so latest requests appear at the end
for request in filtered_requests.iter().rev() {
print_request_summary(request, !full_body, config.get_body_preview_length()); // Don't show body preview in full body mode
// Reverse the order so latest requests appear at the end
for request in filtered_requests.iter().rev() {
print_request_summary(
request,
!full_body,
config.get_body_preview_length(),
); // Don't show body preview in full body mode
if show_headers {
🤖 Prompt for AI Agents
In src/commands.rs around lines 187 to 189, the call to print_request_summary is
written on a single line which is inconsistent with the file's multi-line
argument formatting and may fail rustfmt; change the call to use the same
multi-line style used elsewhere by placing each argument on its own line (one
line for the function name and opening paren, one line per argument, and a
closing paren/semicolon on its own line) while preserving the boolean negation
and the config.get_body_preview_length() call and keeping the trailing comment.

if show_headers {
print_request_headers(request);
}
Expand Down
33 changes: 33 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ pub struct WebhookConfig {
pub default_interval: u64,
pub show_headers_by_default: bool,
pub show_full_body_by_default: bool,
#[serde(default = "WebhookConfig::default_body_preview_length")]
pub body_preview_length: usize,
}

impl WebhookConfig {
fn default_body_preview_length() -> usize {
80
}
}

impl Config {
Expand Down Expand Up @@ -42,6 +50,7 @@ impl Config {
default_interval: 3,
show_headers_by_default: false,
show_full_body_by_default: false,
body_preview_length: WebhookConfig::default_body_preview_length(),
},
};

Expand All @@ -53,7 +62,31 @@ impl Config {
Ok(default_config)
}

/// Normalize a base URL by removing trailing slash
fn normalize_base_url(url: &str) -> &str {
url.trim_end_matches('/')
}

/// Join URL segments properly without creating double slashes
pub fn join_url_segments(base: &str, segments: &[&str]) -> String {
let normalized_base = Self::normalize_base_url(base);
let mut url = normalized_base.to_string();

for segment in segments {
if !segment.is_empty() {
url.push('/');
url.push_str(segment);
}
}

url
}

pub fn get_base_url(&self) -> &str {
&self.webhook.base_url
}

pub fn get_body_preview_length(&self) -> usize {
self.webhook.body_preview_length
}
}
Loading