Files
craft-anything/crates/analysis/tests/har_transfer_sizes.rs
Afloat 9a1dfd0d65 Count received HAR response bytes separately from decoded content (R3.13) (#1327)
A HAR summary added the larger of each response's received and decoded sizes into one total. It now reports the received bytes and the decoded content bytes separately, with how many responses didn't record each.
2026-11-09 20:16:11 +08:00

23 lines
1.1 KiB
Rust

use craft_anything_analysis::web_har::{HarOptions, inspect_har};
use serde_json::json;
#[test]
fn received_and_decoded_sizes_stay_separate() {
let responses = [
json!({"status": 200, "bodySize": 25, "content": {"size": 100}}),
json!({"status": 304, "bodySize": 0, "content": {"size": 120}}),
json!({"status": 200, "bodySize": -1, "content": {"size": 50}}),
json!({"status": 200, "bodySize": 8, "content": {"size": -1}}),
json!({"status": 200, "content": {}}),
];
let entries: Vec<_> =
responses.into_iter().map(|response| json!({"request": {"method": "GET", "url": "https://example.test/"}, "response": response})).collect();
let bytes = serde_json::to_vec(&json!({"log": {"entries": entries}})).unwrap();
let report = inspect_har(&bytes, &HarOptions { max_entries: 10, limit: 10, ..Default::default() }).unwrap();
let summary = &report["summary"];
assert_eq!(summary["response_body_bytes"], 33);
assert_eq!(summary["responses_without_body_size"], 2);
assert_eq!(summary["response_content_bytes"], 270);
assert_eq!(summary["responses_without_content_size"], 2);
}