diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -87,10 +87,10 @@ pub async fn filter_request( // split path into at most 3 chunks let mut req_path = parts.uri.path(); - if req_path.starts_with("/") { + if req_path.starts_with('/') { req_path = &req_path[1..]; } - let path_chunks: Vec<&str> = req_path.split("/").collect(); + let path_chunks: Vec<&str> = req_path.split('/').collect(); if path_chunks.len() > 3 { return Err(ProxyError::NotSupported( "only request paths with up to three segments allowed".to_string(), @@ -143,16 +143,16 @@ pub async fn filter_request( | (&Method::OPTIONS, [index, ""]) => { filter_read_request(index, path_chunks[1], ¶ms, config)? } - (&Method::GET, [index]) - | (&Method::HEAD, [index]) - | (&Method::OPTIONS, [index]) => { + (&Method::GET, [index]) | (&Method::HEAD, [index]) | (&Method::OPTIONS, [index]) => { // only allow operations on index name (no trailing slash) if not "unsafe_all_indices" // (aka, only if indexes are explicitly enumerated) // otherwise all top-level API endpoints would be allowed if config.unsafe_all_indices != Some(true) { filter_read_request(index, "", ¶ms, config)? } else { - Err(ProxyError::NotSupported("unknown elasticsearch API endpoint".to_string()))? + return Err(ProxyError::NotSupported( + "unknown elasticsearch API endpoint".to_string(), + )); } } (&Method::GET, [index, "_mapping"]) @@ -166,7 +166,7 @@ pub async fn filter_request( }; let upstream_query = serde_urlencoded::to_string(params).expect("re-encoding URL parameters"); - let upstream_query_and_params = if upstream_query.len() > 0 { + let upstream_query_and_params = if !upstream_query.is_empty() { format!("{}?{}", req_path, upstream_query) } else { req_path.to_string() @@ -198,7 +198,7 @@ pub fn filter_scroll_request( body: &[u8], _config: &ProxyConfig, ) -> Result<Body, ProxyError> { - if body.len() > 0 { + if !body.is_empty() { let parsed: parse::ScrollBody = serde_json::from_slice(body).map_err(|e| ProxyError::ParseError(e.to_string()))?; // check that scroll_id is not "_all" or too short @@ -250,7 +250,7 @@ pub fn filter_search_request( return Err(ProxyError::UnknownIndex(index.to_string())); } // XXX: more checks - if body.len() > 0 { + if !body.is_empty() { let parsed: parse::SearchBody = serde_json::from_slice(body).map_err(|e| ProxyError::ParseError(e.to_string()))?; Ok(Body::from(serde_json::to_string(&parsed).unwrap())) |