Skip to content

Commit faee02f

Browse files
committed
feat: [#675] tracker checker (HTTP tracker) supports more service address formats
Now it supports a path prefix. It will be remove by the client to build the "scrape" URLs. This type of URL is very common in tracker lists like in https://newtrackon.com/. ```console TORRUST_CHECKER_CONFIG='{ "udp_trackers": [], "http_trackers": [ "http://127.0.0.1:7070", "http://127.0.0.1:7070/", "http://127.0.0.1:7070/announce" ], "health_checks": [] }' cargo run --bin tracker_checker ```
1 parent 520026d commit faee02f

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/console/clients/checker/checks/http.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,24 @@ pub async fn run(http_trackers: Vec<Url>, timeout: Duration) -> Vec<Result<Check
2828
tracing::debug!("HTTP trackers ...");
2929

3030
for ref url in http_trackers {
31+
let mut base_url = url.clone();
32+
base_url.set_path("");
33+
3134
let mut checks = Checks {
3235
url: url.clone(),
3336
results: Vec::default(),
3437
};
3538

3639
// Announce
3740
{
38-
let check = check_http_announce(url, timeout).await.map(|_| ());
41+
let check = check_http_announce(&base_url, timeout).await.map(|_| ());
3942

4043
checks.results.push((Check::Announce, check));
4144
}
4245

4346
// Scrape
4447
{
45-
let check = check_http_scrape(url, timeout).await.map(|_| ());
48+
let check = check_http_scrape(&base_url, timeout).await.map(|_| ());
4649

4750
checks.results.push((Check::Scrape, check));
4851
}

src/console/clients/checker/config.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mod tests {
215215
}
216216

217217
mod http_trackers {
218-
use crate::console::clients::checker::config::{Configuration, PlainConfiguration};
218+
use crate::console::clients::checker::config::{Configuration, PlainConfiguration, ServiceUrl};
219219

220220
#[test]
221221
fn it_should_fail_when_a_tracker_http_url_is_invalid() {
@@ -227,6 +227,41 @@ mod tests {
227227

228228
assert!(Configuration::try_from(plain_config).is_err());
229229
}
230+
231+
#[test]
232+
fn it_should_allow_the_url_to_contain_a_path() {
233+
// This is the common format for HTTP tracker URLs:
234+
// http://domain.com:7070/announce
235+
236+
let plain_config = PlainConfiguration {
237+
udp_trackers: vec![],
238+
http_trackers: vec!["http://127.0.0.1:7070/announce".to_string()],
239+
health_checks: vec![],
240+
};
241+
242+
let config = Configuration::try_from(plain_config).expect("Invalid plain configuration");
243+
244+
assert_eq!(
245+
config.http_trackers[0],
246+
"http://127.0.0.1:7070/announce".parse::<ServiceUrl>().unwrap()
247+
);
248+
}
249+
250+
#[test]
251+
fn it_should_allow_the_url_to_contain_an_empty_path() {
252+
let plain_config = PlainConfiguration {
253+
udp_trackers: vec![],
254+
http_trackers: vec!["http://127.0.0.1:7070/".to_string()],
255+
health_checks: vec![],
256+
};
257+
258+
let config = Configuration::try_from(plain_config).expect("Invalid plain configuration");
259+
260+
assert_eq!(
261+
config.http_trackers[0],
262+
"http://127.0.0.1:7070/".parse::<ServiceUrl>().unwrap()
263+
);
264+
}
230265
}
231266

232267
mod health_checks {

0 commit comments

Comments
 (0)