diff --git a/launchdarkly-server-sdk/src/feature_requester.rs b/launchdarkly-server-sdk/src/feature_requester.rs index 5474870..97e2341 100644 --- a/launchdarkly-server-sdk/src/feature_requester.rs +++ b/launchdarkly-server-sdk/src/feature_requester.rs @@ -1,5 +1,6 @@ use crate::reqwest::is_http_error_recoverable; use futures::future::BoxFuture; +use hyper::body::HttpBody; use hyper::Body; use std::collections::HashMap; use std::sync::Arc; @@ -77,7 +78,7 @@ where .request(request_builder.body(Body::empty()).unwrap()) .await; - let response = match result { + let mut response = match result { Ok(response) => response, Err(e) => { // It appears this type of error will not be an HTTP error. @@ -101,15 +102,16 @@ where .map_or_else(|_| "".into(), |s| s.into()); if response.status().is_success() { - let bytes = hyper::body::to_bytes(response.into_body()) - .await - .map_err(|e| { - error!( - "An error occurred while reading the polling response body: {}", - e - ); - FeatureRequesterError::Temporary - })?; + let mut bytes = Vec::new(); + while let Some(chunk) = response.body_mut().data().await { + match chunk { + Ok(chunk) => bytes.extend(chunk.as_ref()), + Err(e) => { + error!("An error occurred while fetching response data: {}", e); + return Err(FeatureRequesterError::Temporary); + } + } + } let json = serde_json::from_slice::>(bytes.as_ref()); return match json {