From 8eecb3317d89ea4639ac65ea9f68acbec35e915e Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Fri, 6 Oct 2023 19:12:16 +1100 Subject: [PATCH] Fix HTTP missing key handling --- src/storage/store/http.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/storage/store/http.rs b/src/storage/store/http.rs index fdd9f90..5428136 100644 --- a/src/storage/store/http.rs +++ b/src/storage/store/http.rs @@ -99,9 +99,9 @@ impl ReadableStorageTraits for HTTPStore { ) -> Result>>, StorageError> { let url = self.key_to_url(key)?; let client = reqwest::blocking::Client::new(); - let size = self - .size_key(key)? - .ok_or(StorageError::UnknownKeySize(key.clone()))?; + let Some(size) = self.size_key(key)? else { + return Ok(None); + }; let bytes_strs = byte_ranges .iter() .map(|byte_range| format!("{}-{}", byte_range.start(size), byte_range.end(size) - 1)) @@ -111,7 +111,7 @@ impl ReadableStorageTraits for HTTPStore { let response = client.get(url).header(RANGE, range).send()?; match response.status() { - StatusCode::NOT_FOUND => Ok(None), + StatusCode::NOT_FOUND => Err(StorageError::from("the http server returned a NOT FOUND status for the byte range request, but returned a non zero size for CONTENT_LENGTH")), StatusCode::PARTIAL_CONTENT => { // TODO: Gracefully handle a response from the server which does not include all requested by ranges let mut bytes = response.bytes()?; @@ -179,6 +179,7 @@ impl ReadableStorageTraits for HTTPStore { .ok_or(StorageError::from("content length response is invalid"))?; Ok(Some(length)) } + StatusCode::NOT_FOUND => Ok(None), _ => Err(StorageError::from(format!( "http size_key has status code {}", response.status() @@ -256,7 +257,11 @@ mod tests { let data_2x2 = array .retrieve_array_subset_elements::(&subset_2x2) .unwrap(); - assert_eq!(data_2x2, &[0.1, f32::NAN, 0.4, 0.5]); + // assert_eq!(data_2x2, &[0.1, f32::NAN, 0.4, 0.5]); + assert_eq!(data_2x2[0], 0.1); + assert!(data_2x2[1].is_nan()); + assert_eq!(data_2x2[2], 0.4); + assert_eq!(data_2x2[3], 0.5); // let data = array.retrieve_array_subset_ndarray::(&ArraySubset::new_with_shape(array.shape().to_vec())).unwrap(); // println!("{data:?}");