diff options
author | Alex <alex@adnab.me> | 2023-01-30 10:50:47 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2023-01-30 10:50:47 +0000 |
commit | 4d3a5f29e08364c6854eaefbe1e7ca48228dcf32 (patch) | |
tree | a307744981862606cf799eb45c4e65abc0f53f9d /src/api/admin/api_server.rs | |
parent | df30f3df4b2b6cb67c4e37117fb30d6f61cfefc5 (diff) | |
parent | 9c354f0a8ff258872aa3a4b7c116e1d66815afd1 (diff) | |
download | garage-4d3a5f29e08364c6854eaefbe1e7ca48228dcf32.tar.gz garage-4d3a5f29e08364c6854eaefbe1e7ca48228dcf32.zip |
Merge pull request 'api_server.rs: Adapted to use query string per Caddy upstream change' (#491) from jpds/garage:fix-caddy-ask-domain-query-string into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/491
Diffstat (limited to 'src/api/admin/api_server.rs')
-rw-r--r-- | src/api/admin/api_server.rs | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/src/api/admin/api_server.rs b/src/api/admin/api_server.rs index a115d732..58dd38d8 100644 --- a/src/api/admin/api_server.rs +++ b/src/api/admin/api_server.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::net::SocketAddr; use std::sync::Arc; @@ -81,29 +82,32 @@ impl AdminApiServer { &self, req: Request<Body>, ) -> Result<Response<Body>, Error> { - let has_domain_header = req.headers().contains_key("domain"); - - if !has_domain_header { - return Err(Error::bad_request("No domain header found")); + let query_params: HashMap<String, String> = req + .uri() + .query() + .map(|v| { + url::form_urlencoded::parse(v.as_bytes()) + .into_owned() + .collect() + }) + .unwrap_or_else(HashMap::new); + + let has_domain_key = query_params.contains_key("domain"); + + if !has_domain_key { + return Err(Error::bad_request("No domain query string found")); } - let domain = &req - .headers() + let domain = query_params .get("domain") - .ok_or_internal_error("Could not parse domain header")?; - - let domain_string = String::from( - domain - .to_str() - .ok_or_bad_request("Invalid characters found in domain header")?, - ); + .ok_or_internal_error("Could not parse domain query string")?; let bucket_id = self .garage .bucket_helper() - .resolve_global_bucket_name(&domain_string) + .resolve_global_bucket_name(&domain) .await? - .ok_or(HelperError::NoSuchBucket(domain_string))?; + .ok_or(HelperError::NoSuchBucket(domain.to_string()))?; let bucket = self .garage @@ -115,12 +119,16 @@ impl AdminApiServer { let bucket_website_config = bucket_state.website_config.get(); match bucket_website_config { - Some(_v) => Ok(Response::builder() - .status(StatusCode::OK) - .body(Body::from("Bucket authorized for website hosting"))?), - None => Err(Error::bad_request( - "Bucket is not authorized for website hosting", - )), + Some(_v) => { + Ok(Response::builder() + .status(StatusCode::OK) + .body(Body::from(format!( + "Bucket '{domain}' is authorized for website hosting" + )))?) + } + None => Err(Error::bad_request(format!( + "Bucket '{domain}' is not authorized for website hosting" + ))), } } |