Skip to content

Commit

Permalink
Normalize trailing slash of public_server_url
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Nov 11, 2024
1 parent 22900ba commit 020ff8d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
15 changes: 11 additions & 4 deletions bbox-feature-server/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::collections::HashMap;
pub struct Inventory {
// Key: collection_id
feat_collections: HashMap<String, FeatureCollection>,
public_server_url: Option<String>,
base_url: String,
}

#[derive(Clone)]
Expand All @@ -37,18 +37,25 @@ pub struct FeatureCollection {

impl Inventory {
pub fn new(public_server_url: Option<String>) -> Self {
let base_url = format!(
"{}/",
public_server_url
.as_deref()
.unwrap_or("")
.trim_end_matches('/')
);
Inventory {
feat_collections: HashMap::new(),
public_server_url,
base_url,
}
}

pub fn base_url(&self) -> &str {
self.public_server_url.as_deref().unwrap_or("/")
&self.base_url
}

pub fn href_prefix(&self) -> &str {
self.public_server_url.as_deref().unwrap_or("")
self.base_url.trim_end_matches('/')
}

pub async fn scan(config: &CollectionsCfg, public_server_url: Option<String>) -> Inventory {
Expand Down
18 changes: 16 additions & 2 deletions bbox-map-server/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde_xml_rs::from_reader;
#[derive(Serialize, Clone, Default, Debug)]
pub struct Inventory {
pub wms_services: Vec<WmsService>,
pub public_server_url: Option<String>,
base_url: String,
}

#[derive(Serialize, Clone, Debug)]
Expand All @@ -23,8 +23,22 @@ pub enum CapType {
}

impl Inventory {
pub fn new(wms_services: Vec<WmsService>, public_server_url: Option<String>) -> Self {
let base_url = format!(
"{}/",
public_server_url
.as_deref()
.unwrap_or("")
.trim_end_matches('/')
);
Inventory {
wms_services,
base_url,
}
}

pub fn base_url(&self) -> &str {
self.public_server_url.as_deref().unwrap_or("/")
&self.base_url
}
}

Expand Down
5 changes: 1 addition & 4 deletions bbox-map-server/src/wms_fcgi_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ pub fn detect_backends(
);
}
}
let inventory = Inventory {
wms_services: wms_inventory,
public_server_url,
};
let inventory = Inventory::new(wms_inventory, public_server_url);
Ok((pools, inventory))
}

0 comments on commit 020ff8d

Please sign in to comment.