From 31b0286562c11a33ab24e369bf7faa88e299f017 Mon Sep 17 00:00:00 2001 From: Alexander Alexandrov Date: Wed, 13 Mar 2024 12:47:27 +0200 Subject: [PATCH 1/2] Fix a bug in `HyperFeatureRequester::get_all()` The `FeatureRequester::get_all()` implementation for the `HyperFeatureRequester` is currently reading the entire response (as a test try a payload that is more than 8000 bytes long). --- .../src/feature_requester.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/launchdarkly-server-sdk/src/feature_requester.rs b/launchdarkly-server-sdk/src/feature_requester.rs index 5474870..4712fa9 100644 --- a/launchdarkly-server-sdk/src/feature_requester.rs +++ b/launchdarkly-server-sdk/src/feature_requester.rs @@ -101,15 +101,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 { From b35ad81a781f7eced04765cc6229ba13f1804669 Mon Sep 17 00:00:00 2001 From: Matthew Keeler Date: Wed, 13 Mar 2024 12:28:28 -0400 Subject: [PATCH 2/2] Add missing use and mut modifier --- launchdarkly-server-sdk/src/feature_requester.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launchdarkly-server-sdk/src/feature_requester.rs b/launchdarkly-server-sdk/src/feature_requester.rs index 4712fa9..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.