Skip to content

Commit f6673ba

Browse files
committed
Refactor host stats formatters to remove unused parameters and improve example formatting in README
1 parent cb6eac6 commit f6673ba

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,18 @@ Options:
455455
456456
This limits how many requests can be sent simultaneously to the same host (domain/subdomain). This helps prevent overwhelming servers and getting rate-limited. Each host is handled independently.
457457
458-
Examples: --default-host-concurrency 5 # Conservative for slow APIs --default-host-concurrency 20 # Aggressive for fast APIs
458+
Examples:
459+
• --default-host-concurrency 5 # Conservative for slow APIs
460+
• --default-host-concurrency 20 # Aggressive for fast APIs
459461
460462
--default-request-interval <DEFAULT_REQUEST_INTERVAL>
461463
Minimum interval between requests to the same host (default: 100ms)
462464
463465
Sets a baseline delay between consecutive requests to prevent hammering servers. The adaptive algorithm may increase this based on server responses (rate limits, errors).
464466
465-
Examples: --default-request-interval 50ms # Fast for robust APIs\ --default-request-interval 1s # Conservative for rate-limited APIs
467+
Examples:
468+
• --default-request-interval 50ms # Fast for robust APIs
469+
• --default-request-interval 1s # Conservative for rate-limited APIs
466470
467471
-T, --threads <THREADS>
468472
Number of threads to utilize. Defaults to number of cores available to the system

lychee-bin/src/client.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,20 @@ pub(crate) fn create(cfg: &Config, cookie_jar: Option<&Arc<CookieStoreMutex>>) -
4444
let rate_limit_config =
4545
RateLimitConfig::from_options(cfg.default_host_concurrency, cfg.default_request_interval);
4646
let cache_max_age = if cfg.cache { 3600 } else { 0 }; // 1 hour if caching enabled, disabled otherwise
47-
let host_pool = match cookie_jar {
48-
Some(cookie_jar) => HostPool::with_cookie_jar(
47+
let host_pool = if let Some(cookie_jar) = cookie_jar {
48+
HostPool::with_cookie_jar(
4949
rate_limit_config,
5050
cfg.hosts.clone(),
5151
cfg.max_concurrency,
5252
cache_max_age,
53-
combined_headers,
53+
combined_headers.clone(),
5454
cfg.max_redirects,
5555
Some(timeout),
5656
cfg.insecure,
5757
cookie_jar.clone(),
58-
),
59-
None => HostPool::new(
58+
)
59+
} else {
60+
HostPool::new(
6061
rate_limit_config,
6162
cfg.hosts.clone(),
6263
cfg.max_concurrency,
@@ -65,7 +66,7 @@ pub(crate) fn create(cfg: &Config, cookie_jar: Option<&Arc<CookieStoreMutex>>) -
6566
cfg.max_redirects,
6667
Some(timeout),
6768
cfg.insecure,
68-
),
69+
)
6970
};
7071

7172
ClientBuilder::builder()

lychee-bin/src/formatters/host_stats/compact.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{
55
};
66

77
use crate::formatters::color::{DIM, NORMAL, color};
8-
use crate::options;
98
use lychee_lib::ratelimit::HostStats;
109

1110
use super::HostStatsFormatter;
@@ -65,7 +64,7 @@ impl Display for CompactHostStats {
6564
pub(crate) struct Compact;
6665

6766
impl Compact {
68-
pub(crate) const fn new(_mode: options::OutputMode) -> Self {
67+
pub(crate) const fn new() -> Self {
6968
Self
7069
}
7170
}

lychee-bin/src/formatters/host_stats/detailed.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
fmt::{self, Display},
55
};
66

7-
use crate::options;
87
use lychee_lib::ratelimit::HostStats;
98

109
use super::HostStatsFormatter;
@@ -35,7 +34,11 @@ impl Display for DetailedHostStats {
3534
)?;
3635

3736
if stats.rate_limited > 0 {
38-
writeln!(f, " Rate limited: {}", stats.rate_limited)?;
37+
writeln!(
38+
f,
39+
" Rate limited: {} (429 Too Many Requests)",
40+
stats.rate_limited
41+
)?;
3942
}
4043
if stats.client_errors > 0 {
4144
writeln!(f, " Client errors (4xx): {}", stats.client_errors)?;
@@ -70,7 +73,7 @@ impl Display for DetailedHostStats {
7073
pub(crate) struct Detailed;
7174

7275
impl Detailed {
73-
pub(crate) const fn new(_mode: options::OutputMode) -> Self {
76+
pub(crate) const fn new() -> Self {
7477
Self
7578
}
7679
}

lychee-bin/src/formatters/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ pub(crate) fn get_stats_formatter(
3333
/// Create a host stats formatter based on the given format and mode options
3434
pub(crate) fn get_host_stats_formatter(
3535
format: &StatsFormat,
36-
mode: &OutputMode,
36+
_mode: &OutputMode,
3737
) -> Box<dyn HostStatsFormatter> {
3838
match format {
39-
StatsFormat::Compact | StatsFormat::Raw => Box::new(host_stats::Compact::new(mode.clone())), // Use compact for raw
40-
StatsFormat::Detailed => Box::new(host_stats::Detailed::new(mode.clone())),
39+
StatsFormat::Compact | StatsFormat::Raw => Box::new(host_stats::Compact::new()), // Use compact for raw
40+
StatsFormat::Detailed => Box::new(host_stats::Detailed::new()),
4141
StatsFormat::Json => Box::new(host_stats::Json::new()),
4242
StatsFormat::Markdown => Box::new(host_stats::Markdown::new()),
4343
}

lychee-bin/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ impl Config {
929929
// Keys which are handled outside of fold_in
930930
..header,
931931
..github_token,
932+
..hosts,
932933

933934
// Keys with defaults to assign
934935
accept: StatusCodeSelector::default(),
@@ -957,7 +958,6 @@ impl Config {
957958
glob_ignore_case: false,
958959
hidden: false,
959960
host_stats: false,
960-
hosts: HashMap::new(),
961961
include: Vec::<String>::new(),
962962
include_fragments: false,
963963
include_mail: false,

0 commit comments

Comments
 (0)