magi-code 0.103.0

Repository-aware CLI coding agent for terminal work
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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)
}