fix: function source query params parse

This commit is contained in:
Stepan Kuzmin 2018-10-18 20:05:33 +03:00
parent 73d8e86860
commit 8ac2812d05

View File

@ -16,12 +16,13 @@ pub fn build_tilejson(
) -> Result<TileJSON, ToStrError> { ) -> Result<TileJSON, ToStrError> {
let source_id = source.get_id(); let source_id = source.get_id();
let path = headers let path =
.get("x-rewrite-url") headers
.map_or(Ok(path.trim_right_matches(".json")), |header| { .get("x-rewrite-url")
let header_str = header.to_str()?; .map_or(Ok(path.trim_right_matches(".json")), |header| {
Ok(header_str.trim_right_matches(".json")) let header_str = header.to_str()?;
})?; Ok(header_str.trim_right_matches(".json"))
})?;
let query = if query_string.is_empty() { let query = if query_string.is_empty() {
query_string.to_owned() query_string.to_owned()
@ -99,7 +100,9 @@ pub fn json_to_hashmap(value: &serde_json::Value) -> HashMap<String, String> {
pub fn query_to_json_string(query: &Query) -> Result<String, serde_json::Error> { pub fn query_to_json_string(query: &Query) -> Result<String, serde_json::Error> {
let mut query_as_json = HashMap::new(); let mut query_as_json = HashMap::new();
for (k, v) in query.iter() { for (k, v) in query.iter() {
let json_value: serde_json::Value = serde_json::from_str(v)?; let json_value: serde_json::Value =
serde_json::from_str(v).unwrap_or_else(|_| serde_json::Value::String(v.clone()));
query_as_json.insert(k, json_value); query_as_json.insert(k, json_value);
} }