···1010http = "1.3.1"
1111ntex = { version = "2.16.0", features = ["tokio"] }
1212regex = "1.11.3"
1313-reqwest = {version = "0.12.23", features = ["json"] }
1413serde = {version ="1.0.228", features = ["derive"] }
1514serde_json = "1.0.145"
1615tracing = "0.1.41"
+28-14
src/docker.rs
···55use crate::config::{ContainerLabels, ContainerNames};
66use crate::utils;
7788+use ntex::{http::{self}, web::{self}};
99+810pub mod types;
9111012pub struct GetMatch {
···5153 return match_labels_or_names(container_names, container_labels, &container.names.as_ref().unwrap_or(Vec::new().as_ref()), &container.labels.as_ref().unwrap_or(&HashMap::<String,String>::new()))
5254}
53555454-pub async fn get_container_info(u: &String, container_id: &String) -> Result<(String, HashMap<String,String>), Box<dyn std::error::Error>> {
5656+pub async fn get_container_info(client: &web::types::State<http::Client>, u: &web::types::State<url::Url>, container_id: &String) -> Result<(String, HashMap<String,String>), Box<dyn std::error::Error>> {
55575656- let url = format!("{}containers/{id}/json", u, id = container_id);
5757- let resp = reqwest::get(&url)
5858- .await?
5959- .json::<types::ContainerInspect>()
6060- .await;
6161- match resp {
6262- Ok(json_res) => {
6363- if json_res.message.is_some() {
6464- return Err(json_res.message.unwrap().into())
5858+ let mut uri = u.get_ref().clone();
5959+ uri.set_path(format!("containers/{id}/json", id = container_id).as_str());
6060+6161+ let mut res = client.get(uri.to_string())
6262+ .send()
6363+ .await;
6464+ // .map_err(web::Error::from)?;
6565+6666+ match res {
6767+ Ok(mut okres) => {
6868+ let info_res = okres.json::<types::ContainerInspect>()
6969+ .limit(2097152).await;
7070+ match info_res {
7171+ Ok(json_res) => {
7272+ if json_res.message.is_some() {
7373+ return Err(json_res.message.unwrap().into())
7474+ }
7575+ Ok((json_res.name.expect("Container has a name"), json_res.config.expect("Container has config").labels.expect("Container has labels")))
7676+ },
7777+ Err(e) => {
7878+ return Err(Box::new(e));
6579 }
6666- Ok((json_res.name.expect("Container has a name"), json_res.config.expect("Container has config").labels.expect("Container has labels")))
6780 }
6868- Err(e) => {
6969- return Err(Box::new(e));
7070- }
8181+ },
8282+ Err(e) => {
8383+ return Err(Box::new(e));
7184 }
8585+ }
7286}
+1-1
src/proxy.rs
···8888 // or if we encountered an error last time then try again
8989 if !cm.contains_key(&m.id) || cm.get(&m.id).unwrap().is_none() {
9090 debug!("Requested Id not in map, trying to inspect...");
9191- let info_res = docker::get_container_info(&forward_url.to_string(), &m.id).await;
9191+ let info_res = docker::get_container_info(&client, &forward_url, &m.id).await;
9292 match info_res {
9393 Ok((name, labels)) => {
9494 let is_container_match = docker::match_labels_or_names(&app_config.get_ref().container_names, &app_config.get_ref().container_labels, &Vec::from([name.clone()]), &labels);