use std::io::Read;
pub(crate) const DEFAULT_BOUNDED_BODY_MAX_BYTES: u64 = 2 * 1024 * 1024;
pub(crate) fn read_bounded_response_text(
response: reqwest::blocking::Response,
max_bytes: u64,
) -> anyhow::Result<String> {
let mut bounded = response.take(max_bytes + 1);
let mut text = String::new();
bounded.read_to_string(&mut text)?;
if text.len() as u64 > max_bytes {
anyhow::bail!("response exceeded {max_bytes} bytes");
}
Ok(text)
}