From 2c9c3ddb905a5c2cdf89082ec93ca5d97816c2f8 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 26 Dec 2023 17:24:40 +0000 Subject: [PATCH 1/2] fix: [#391] patch to identify 'torrent not found' tracker API response --- src/tracker/service.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tracker/service.rs b/src/tracker/service.rs index 6c89ed09..19ac3b95 100644 --- a/src/tracker/service.rs +++ b/src/tracker/service.rs @@ -184,7 +184,7 @@ async fn map_torrent_info_response(response: Response) -> Result Date: Tue, 26 Dec 2023 17:26:02 +0000 Subject: [PATCH 2/2] fix: [#419] url-encode tracker API token in the HTTP requests When the tracker API token contains specials characters, the token must be URL-encoded. For example: Wrong URL: http://tracker.torrust-demo.com:1212/v1/stats?token=123g7#@agJtWFSgkdA5R$K22yeo$k6IhNq%T2$r Rigth URL with encoded token: http://tracker.torrust-demo.com:1212/v1/stats?token=123g7%23%40agJtWFSgkdA5R%24K22yeo%24k6IhNq%25T2%24r --- src/tracker/api.rs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/tracker/api.rs b/src/tracker/api.rs index d3fa3fcb..f64430b7 100644 --- a/src/tracker/api.rs +++ b/src/tracker/api.rs @@ -34,14 +34,13 @@ impl Client { /// /// Will return an error if the HTTP request fails. pub async fn whitelist_torrent(&self, info_hash: &str) -> Result { - let request_url = format!( - "{}/whitelist/{}?token={}", - self.base_url, info_hash, self.connection_info.token - ); + let request_url = format!("{}/whitelist/{}", self.base_url, info_hash); let client = reqwest::Client::new(); - client.post(request_url).send().await + let params = [("token", &self.connection_info.token)]; + + client.post(request_url).query(¶ms).send().await } /// Remove a torrent from the tracker whitelist. @@ -50,14 +49,13 @@ impl Client { /// /// Will return an error if the HTTP request fails. pub async fn remove_torrent_from_whitelist(&self, info_hash: &str) -> Result { - let request_url = format!( - "{}/whitelist/{}?token={}", - self.base_url, info_hash, self.connection_info.token - ); + let request_url = format!("{}/whitelist/{}", self.base_url, info_hash); let client = reqwest::Client::new(); - client.delete(request_url).send().await + let params = [("token", &self.connection_info.token)]; + + client.delete(request_url).query(¶ms).send().await } /// Retrieve a new tracker key. @@ -66,14 +64,13 @@ impl Client { /// /// Will return an error if the HTTP request fails. pub async fn retrieve_new_tracker_key(&self, token_valid_seconds: u64) -> Result { - let request_url = format!( - "{}/key/{}?token={}", - self.base_url, token_valid_seconds, self.connection_info.token - ); + let request_url = format!("{}/key/{}", self.base_url, token_valid_seconds); let client = reqwest::Client::new(); - client.post(request_url).send().await + let params = [("token", &self.connection_info.token)]; + + client.post(request_url).query(¶ms).send().await } /// Retrieve the info for a torrent. @@ -82,10 +79,12 @@ impl Client { /// /// Will return an error if the HTTP request fails. pub async fn get_torrent_info(&self, info_hash: &str) -> Result { - let request_url = format!("{}/torrent/{}?token={}", self.base_url, info_hash, self.connection_info.token); + let request_url = format!("{}/torrent/{}", self.base_url, info_hash); let client = reqwest::Client::new(); - client.get(request_url).send().await + let params = [("token", &self.connection_info.token)]; + + client.get(request_url).query(¶ms).send().await } }