Skip to main content

agent_first_http/sdk/fetch/artifacts/
network_bodies.rs

1//! Opt-in network response body capture under `network-bodies/`.
2
3use std::path::PathBuf;
4
5use crate::sdk::fetch::writer;
6use crate::shared::artifacts::ArtifactPaths;
7use crate::shared::error::Error;
8
9/// Write a single response body. `request_id` is the CDP-assigned id used
10/// as the filename stem; callers pick the extension from the mime type.
11pub async fn write(
12    paths: &ArtifactPaths,
13    request_id: &str,
14    ext: &str,
15    bytes: &[u8],
16) -> Result<PathBuf, Error> {
17    let dir = paths.network_bodies_dir();
18    writer::ensure_dir(&dir).await?;
19    let target = dir.join(format!("{request_id}.{ext}"));
20    writer::write_bytes(&target, bytes).await?;
21    Ok(target)
22}