wafrift-proxy 0.2.3

HTTP forward proxy with automatic WAF evasion and optional TLS interception support.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
//! Flow tab — live request stream with optional detail pane.
//!
//! Layout when no inspect:
//!   ┌─ Requests ──────────────┐
//!   │ ▶ rows...               │
//!   ├─ req/s ─┬─ bypasses/s ──┤
//!   └─────────┴───────────────┘
//!
//! With inspect, the right column hosts the detail pane.

use ratatui::Frame;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Clear, Paragraph, Sparkline, Wrap};

use super::format::{outcome_color, status_color, truncate};
use super::state::{RequestRecord, State};

pub fn draw(f: &mut Frame, area: Rect, state: &State) {
    let detail_open = state.inspect && state.selected.is_some();
    let cols = if detail_open {
        Layout::default()
            .direction(Direction::Horizontal)
            .constraints([Constraint::Percentage(55), Constraint::Percentage(45)])
            .split(area)
    } else {
        Layout::default()
            .direction(Direction::Horizontal)
            .constraints([Constraint::Percentage(100)])
            .split(area)
    };

    let left = Layout::default()
        .direction(Direction::Vertical)
        .constraints([Constraint::Min(5), Constraint::Length(6)])
        .split(cols[0]);

    draw_request_list(f, left[0], state);
    draw_sparklines(f, left[1], state);

    if detail_open {
        draw_detail(f, cols[1], state);
    }
}

fn draw_request_list(f: &mut Frame, area: Rect, state: &State) {
    let visible = state.visible_indices();
    let block = Block::default()
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::DarkGray))
        .title(Span::styled(
            format!(" Requests · {} of {} ", visible.len(), state.recent.len()),
            Style::default()
                .fg(Color::LightCyan)
                .add_modifier(Modifier::BOLD),
        ));
    let inner = block.inner(area);
    f.render_widget(block, area);

    if state.recent.is_empty() {
        let p = Paragraph::new("(no requests yet — proxy a request through this address)")
            .style(Style::default().fg(Color::DarkGray));
        f.render_widget(p, inner);
        return;
    }
    if visible.is_empty() {
        let p = Paragraph::new("(filter matches nothing — `/` to edit, `o` to cycle outcome)")
            .style(Style::default().fg(Color::DarkGray));
        f.render_widget(p, inner);
        return;
    }

    let inner_h = inner.height as usize;
    let total = visible.len();
    // Anchor visible window around the selected row when present.
    let anchor_visible = state
        .selected
        .and_then(|sel| visible.iter().position(|&v| v == sel))
        .unwrap_or(total - 1);
    let start = anchor_visible.saturating_sub(inner_h.saturating_sub(1));
    let window: Vec<usize> = visible.iter().copied().skip(start).take(inner_h).collect();

    let mut lines = Vec::with_capacity(window.len());
    for ridx in window {
        let Some(rec) = state.recent.get(ridx) else {
            continue;
        };
        let is_sel = state.selected == Some(ridx);
        let marker = if is_sel { "" } else { "  " };
        let row_style = if is_sel {
            Style::default()
                .bg(Color::Rgb(28, 32, 40))
                .add_modifier(Modifier::BOLD)
        } else {
            Style::default()
        };
        let path_disp = truncate(&rec.path, 24);
        let host_disp = truncate(&rec.host, 22);
        let line = Line::from(vec![
            Span::styled(marker, Style::default().fg(outcome_color(rec))),
            Span::styled(rec.timestamp.clone(), Style::default().fg(Color::DarkGray)),
            Span::raw(" "),
            Span::styled(
                format!("{:>5}", rec.method),
                Style::default().fg(Color::Cyan),
            ),
            Span::raw(" "),
            Span::styled(
                format!("{path_disp:<24}"),
                Style::default().fg(Color::White),
            ),
            Span::raw(" "),
            Span::styled(format!("{host_disp:<22}"), Style::default().fg(Color::Gray)),
            Span::raw(" "),
            Span::styled(
                format!("{:>3}", rec.status),
                Style::default()
                    .fg(status_color(rec.status))
                    .add_modifier(Modifier::BOLD),
            ),
            Span::raw(" "),
            Span::styled(
                format!("{:<6}", rec.outcome()),
                Style::default().fg(outcome_color(rec)),
            ),
            Span::raw(" "),
            Span::styled(
                format!("{}ms", rec.upstream_latency_ms),
                Style::default().fg(Color::DarkGray),
            ),
            Span::raw(" "),
            Span::styled(
                truncate(&rec.techniques, 30).to_string(),
                Style::default().fg(Color::Magenta),
            ),
        ]);
        lines.push(line.style(row_style));
    }
    f.render_widget(Paragraph::new(lines).wrap(Wrap { trim: false }), inner);
}

fn draw_sparklines(f: &mut Frame, area: Rect, state: &State) {
    let cols = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
        .split(area);

    let req_data: Vec<u64> = state.spark.iter().map(|b| b.requests).collect();
    let bypass_data: Vec<u64> = state.spark.iter().map(|b| b.bypasses).collect();
    let max_req = req_data.iter().copied().max().unwrap_or(1).max(1);
    let max_byp = bypass_data.iter().copied().max().unwrap_or(1).max(1);

    let req_spark = Sparkline::default()
        .block(
            Block::default()
                .borders(Borders::ALL)
                .border_style(Style::default().fg(Color::DarkGray))
                .title(Span::styled(
                    format!(" req/s · 60s · max {max_req} "),
                    Style::default().fg(Color::Cyan),
                )),
        )
        .data(&req_data)
        .style(Style::default().fg(Color::LightCyan));
    f.render_widget(req_spark, cols[0]);

    let byp_spark = Sparkline::default()
        .block(
            Block::default()
                .borders(Borders::ALL)
                .border_style(Style::default().fg(Color::DarkGray))
                .title(Span::styled(
                    format!(" bypasses/s · 60s · max {max_byp} "),
                    Style::default().fg(Color::LightGreen),
                )),
        )
        .data(&bypass_data)
        .style(Style::default().fg(Color::Green));
    f.render_widget(byp_spark, cols[1]);
}

fn draw_detail(f: &mut Frame, area: Rect, state: &State) {
    let Some(idx) = state.selected else { return };
    let Some(rec) = state.recent.get(idx) else {
        return;
    };

    f.render_widget(Clear, area);
    let block = Block::default()
        .borders(Borders::ALL)
        .border_style(Style::default().fg(Color::LightCyan))
        .title(Span::styled(
            format!(
                " Detail · {} {}{} {} · scroll j/k PgUp/Dn ",
                rec.method,
                truncate(&rec.path, 30),
                rec.status,
                rec.outcome()
            ),
            Style::default()
                .fg(Color::LightCyan)
                .add_modifier(Modifier::BOLD),
        ));
    let inner = block.inner(area);
    f.render_widget(block, area);

    // Build a single flat line stream so the scroll offset is a real
    // line index — much simpler than maintaining three independent
    // scroll offsets.
    let lines = render_detail_lines(rec);
    let total = lines.len() as u16;
    let scroll = if total > inner.height {
        state.detail_scroll.min(total - inner.height)
    } else {
        0
    };

    let p = Paragraph::new(lines)
        .wrap(Wrap { trim: false })
        .scroll((scroll, 0));
    f.render_widget(p, inner);
}

/// Build the detail pane as a flat line stream (summary, then outgoing
/// request, then incoming response). Public for unit tests.
pub fn render_detail_lines(rec: &RequestRecord) -> Vec<Line<'static>> {
    let waf_label = rec.waf_name.clone().unwrap_or_else(|| "(unknown)".into());
    let pad_label = if rec.body_padded { "yes" } else { "no" }.to_string();
    let tls_label = rec.tls_profile.clone().unwrap_or_else(|| "(none)".into());

    let mutation_diff = render_mutation_diff(rec);

    let mut lines = vec![
        Line::from(vec![
            label("host"),
            Span::styled(rec.host.clone(), Style::default().fg(Color::Yellow)),
            spacer(),
            label("waf"),
            Span::styled(waf_label, Style::default().fg(Color::LightMagenta)),
        ]),
        Line::from(vec![
            label("attempts"),
            Span::styled(rec.attempts.to_string(), Style::default().fg(Color::White)),
            spacer(),
            label("latency"),
            Span::styled(
                format!("{}ms", rec.upstream_latency_ms),
                Style::default().fg(Color::White),
            ),
            spacer(),
            label("body padding"),
            Span::styled(pad_label, Style::default().fg(Color::Cyan)),
            spacer(),
            label("tls"),
            Span::styled(tls_label, Style::default().fg(Color::LightMagenta)),
        ]),
        Line::from(vec![
            label("techniques"),
            Span::styled(rec.techniques.clone(), Style::default().fg(Color::Magenta)),
        ]),
        Line::from(vec![
            label("response body"),
            Span::styled(
                format!("{} bytes", rec.resp_body_total),
                Style::default().fg(Color::White),
            ),
            spacer(),
            label("excerpt"),
            Span::styled(
                format!("{} bytes", rec.resp_body_excerpt.len()),
                Style::default().fg(Color::White),
            ),
        ]),
        Line::from(""),
        Line::styled(
            "──── ↑ outgoing request ────",
            Style::default().fg(Color::Cyan),
        ),
        Line::from(vec![Span::styled(
            format!("{} {} HTTP/1.1", rec.method, rec.path),
            Style::default()
                .fg(Color::Cyan)
                .add_modifier(Modifier::BOLD),
        )]),
    ];
    for (k, v) in &rec.req_headers {
        lines.push(Line::from(vec![
            Span::styled(format!("{k}: "), Style::default().fg(Color::DarkGray)),
            Span::styled(v.clone(), Style::default().fg(Color::White)),
        ]));
    }
    if !rec.req_body_excerpt.is_empty() {
        lines.push(Line::from(""));
        for body_line in body_lines(&rec.req_body_excerpt, Color::Yellow) {
            lines.push(body_line);
        }
    }

    // ── Mutation diff (#109) ──────────────────────────────────
    // Show what wafrift's evade pipeline changed between
    // client-side request and the bytes that hit the wire. Empty
    // when the proxy was in passthrough (req_headers_pre is empty).
    if !mutation_diff.is_empty() {
        lines.push(Line::from(""));
        lines.push(Line::styled(
            "──── ⇄ evade mutation diff ────",
            Style::default().fg(Color::LightMagenta),
        ));
        for diff_line in mutation_diff {
            lines.push(diff_line);
        }
    }

    lines.push(Line::from(""));
    lines.push(Line::styled(
        "──── ↓ incoming response ────",
        Style::default().fg(status_color(rec.status)),
    ));
    lines.push(Line::from(vec![Span::styled(
        format!("HTTP/1.1 {}", rec.status),
        Style::default()
            .fg(status_color(rec.status))
            .add_modifier(Modifier::BOLD),
    )]));
    for (k, v) in &rec.resp_headers {
        lines.push(Line::from(vec![
            Span::styled(format!("{k}: "), Style::default().fg(Color::DarkGray)),
            Span::styled(v.clone(), Style::default().fg(Color::White)),
        ]));
    }
    if !rec.resp_body_excerpt.is_empty() {
        lines.push(Line::from(""));
        for body_line in body_lines(&rec.resp_body_excerpt, Color::Gray) {
            lines.push(body_line);
        }
    }

    lines
}

/// Build the evade-mutation diff section: header-set difference
/// (added / removed / value-changed) plus a one-line body byte-count
/// delta. Returns empty when no pre-evade snapshot is recorded
/// (passthrough mode).
fn render_mutation_diff(rec: &RequestRecord) -> Vec<Line<'static>> {
    if rec.req_headers_pre.is_empty() && rec.req_body_pre_excerpt.is_empty() {
        return Vec::new();
    }
    let mut out: Vec<Line<'static>> = Vec::new();

    let pre: std::collections::HashMap<String, &str> = rec
        .req_headers_pre
        .iter()
        .map(|(k, v)| (k.to_ascii_lowercase(), v.as_str()))
        .collect();
    let post: std::collections::HashMap<String, &str> = rec
        .req_headers
        .iter()
        .map(|(k, v)| (k.to_ascii_lowercase(), v.as_str()))
        .collect();

    let mut added: Vec<(String, &str)> = Vec::new();
    let mut removed: Vec<(String, &str)> = Vec::new();
    let mut changed: Vec<(String, &str, &str)> = Vec::new();
    for (k, v) in &post {
        match pre.get(k) {
            None => added.push((k.clone(), v)),
            Some(prev) if prev != v => changed.push((k.clone(), prev, v)),
            _ => {}
        }
    }
    for (k, v) in &pre {
        if !post.contains_key(k) {
            removed.push((k.clone(), v));
        }
    }
    added.sort_by(|a, b| a.0.cmp(&b.0));
    removed.sort_by(|a, b| a.0.cmp(&b.0));
    changed.sort_by(|a, b| a.0.cmp(&b.0));

    for (k, v) in &added {
        out.push(Line::from(vec![
            Span::styled("+ ", Style::default().fg(Color::LightGreen)),
            Span::styled(format!("{k}: "), Style::default().fg(Color::Green)),
            Span::styled(v.to_string(), Style::default().fg(Color::White)),
        ]));
    }
    for (k, v) in &removed {
        out.push(Line::from(vec![
            Span::styled("- ", Style::default().fg(Color::LightRed)),
            Span::styled(format!("{k}: "), Style::default().fg(Color::Red)),
            Span::styled(v.to_string(), Style::default().fg(Color::DarkGray)),
        ]));
    }
    for (k, prev, cur) in &changed {
        out.push(Line::from(vec![
            Span::styled("~ ", Style::default().fg(Color::Yellow)),
            Span::styled(format!("{k}: "), Style::default().fg(Color::Yellow)),
            Span::styled(prev.to_string(), Style::default().fg(Color::DarkGray)),
            Span::raw(""),
            Span::styled(cur.to_string(), Style::default().fg(Color::White)),
        ]));
    }

    if !rec.req_body_pre_excerpt.is_empty() || !rec.req_body_excerpt.is_empty() {
        let pre_len = rec.req_body_pre_excerpt.len();
        let post_len = rec.req_body_excerpt.len();
        let symbol = if pre_len == post_len {
            "="
        } else if post_len > pre_len {
            ""
        } else {
            ""
        };
        let body_byte_equal = rec.req_body_pre_excerpt == rec.req_body_excerpt;
        let body_status = if body_byte_equal {
            "byte-identical"
        } else {
            "mutated"
        };
        let body_color = if body_byte_equal {
            Color::DarkGray
        } else {
            Color::Yellow
        };
        out.push(Line::from(vec![
            Span::styled("body ", Style::default().fg(Color::DarkGray)),
            Span::styled(symbol.to_string(), Style::default().fg(body_color)),
            Span::raw(" "),
            Span::styled(
                format!("{pre_len}{post_len} bytes ({body_status})"),
                Style::default().fg(body_color),
            ),
        ]));
    }

    if added.is_empty()
        && removed.is_empty()
        && changed.is_empty()
        && rec.req_body_pre_excerpt == rec.req_body_excerpt
    {
        out.push(Line::from(vec![Span::styled(
            "(no mutation — request passed through unchanged)",
            Style::default().fg(Color::DarkGray),
        )]));
    }
    out
}

fn label(s: &str) -> Span<'static> {
    Span::styled(format!("{s} "), Style::default().fg(Color::DarkGray))
}

fn spacer() -> Span<'static> {
    Span::raw("    ")
}

/// Split a UTF-8 (or lossy) body into lines preserving newlines.
/// Truncates each rendered line to ~200 chars so a one-shot 1KB blob
/// doesn't blow up the wrapped width on narrow terminals.
fn body_lines(bytes: &[u8], color: Color) -> Vec<Line<'static>> {
    let s = String::from_utf8_lossy(bytes);
    s.split('\n')
        .map(|l| {
            let truncated = truncate(l, 200);
            Line::styled(truncated.to_string(), Style::default().fg(color))
        })
        .collect()
}

#[cfg(test)]
mod tests {
    use super::*;

    fn rec() -> RequestRecord {
        RequestRecord {
            timestamp: "00:00:00".into(),
            host: "h".into(),
            method: "GET".into(),
            path: "/".into(),
            status: 200,
            bypassed: true,
            blocked: false,
            techniques: "encoding:UrlEncode".into(),
            tls_profile: Some("chrome131".into()),
            body_padded: true,
            upstream_latency_ms: 7,
            waf_name: Some("Cloudflare".into()),
            req_headers: vec![("X-A".into(), "1".into())],
            req_body_excerpt: b"hello\nworld".to_vec(),
            req_headers_pre: vec![("X-A".into(), "1".into())],
            req_body_pre_excerpt: b"hello\nworld".to_vec(),
            resp_headers: vec![("server".into(), "cloudflare".into())],
            resp_body_excerpt: b"OK".to_vec(),
            resp_body_total: 2,
            attempts: 0,
        }
    }

    #[test]
    fn detail_lines_include_summary_and_both_directions() {
        let lines = render_detail_lines(&rec());
        assert!(lines.iter().any(|l| line_text(l).contains("host")));
        assert!(
            lines
                .iter()
                .any(|l| line_text(l).contains("outgoing request"))
        );
        assert!(
            lines
                .iter()
                .any(|l| line_text(l).contains("GET / HTTP/1.1"))
        );
        assert!(lines.iter().any(|l| line_text(l).contains("X-A:")));
        assert!(
            lines
                .iter()
                .any(|l| line_text(l).contains("incoming response"))
        );
        assert!(lines.iter().any(|l| line_text(l).contains("HTTP/1.1 200")));
        assert!(lines.iter().any(|l| line_text(l).contains("server:")));
    }

    #[test]
    fn body_lines_split_on_newlines() {
        let ls = body_lines(b"a\nb\nc", Color::Yellow);
        assert_eq!(ls.len(), 3);
    }

    fn line_text(l: &Line<'_>) -> String {
        l.spans
            .iter()
            .map(|s| s.content.as_ref())
            .collect::<String>()
    }

    // ── mutation diff (#109) ─────────────────────────────────

    #[test]
    fn mutation_diff_empty_when_no_pre_snapshot_recorded() {
        let mut r = rec();
        r.req_headers_pre.clear();
        r.req_body_pre_excerpt.clear();
        let lines = render_mutation_diff(&r);
        assert!(lines.is_empty(), "must return zero lines on passthrough");
    }

    #[test]
    fn mutation_diff_byte_identical_emits_no_change_marker() {
        // pre == post so diff renderer reports a 'no mutation' line.
        let lines = render_mutation_diff(&rec());
        let body = lines.iter().map(line_text).collect::<Vec<_>>().join("\n");
        assert!(
            body.contains("no mutation"),
            "expected 'no mutation' note when pre == post; got:\n{body}"
        );
    }

    #[test]
    fn mutation_diff_added_header_marked_with_plus() {
        let mut r = rec();
        r.req_headers_pre = vec![("Host".into(), "x".into())];
        r.req_headers = vec![
            ("Host".into(), "x".into()),
            ("X-Forwarded-For".into(), "127.0.0.1".into()),
        ];
        let body = render_mutation_diff(&r)
            .iter()
            .map(line_text)
            .collect::<Vec<_>>()
            .join("\n");
        assert!(
            body.contains("+ x-forwarded-for:"),
            "added header must be tagged: {body}"
        );
        assert!(body.contains("127.0.0.1"));
    }

    #[test]
    fn mutation_diff_removed_header_marked_with_minus() {
        let mut r = rec();
        r.req_headers_pre = vec![
            ("Host".into(), "x".into()),
            ("Cookie".into(), "session=abc".into()),
        ];
        r.req_headers = vec![("Host".into(), "x".into())];
        let body = render_mutation_diff(&r)
            .iter()
            .map(line_text)
            .collect::<Vec<_>>()
            .join("\n");
        assert!(body.contains("- cookie:"), "removed header tagged: {body}");
    }

    #[test]
    fn mutation_diff_changed_header_shows_arrow() {
        let mut r = rec();
        r.req_headers_pre = vec![("User-Agent".into(), "curl/8".into())];
        r.req_headers = vec![("User-Agent".into(), "Mozilla/5.0".into())];
        let body = render_mutation_diff(&r)
            .iter()
            .map(line_text)
            .collect::<Vec<_>>()
            .join("\n");
        assert!(body.contains("~ user-agent:"), "changed header tag: {body}");
        assert!(body.contains("curl/8"), "old value present: {body}");
        assert!(body.contains(""), "arrow separator present: {body}");
        assert!(body.contains("Mozilla/5.0"), "new value present: {body}");
    }

    #[test]
    fn mutation_diff_body_size_delta_reported() {
        let mut r = rec();
        r.req_body_pre_excerpt = b"id=1' OR 1=1".to_vec();
        r.req_body_excerpt = b"id=1%27%20OR%201%3D1".to_vec();
        let body = render_mutation_diff(&r)
            .iter()
            .map(line_text)
            .collect::<Vec<_>>()
            .join("\n");
        assert!(body.contains("body"), "body line present: {body}");
        assert!(
            body.contains("12 → 20 bytes"),
            "byte counts present: {body}"
        );
        assert!(body.contains("mutated"), "mutated label present: {body}");
    }

    #[test]
    fn mutation_diff_byte_identical_body_marked() {
        let mut r = rec();
        r.req_body_pre_excerpt = b"same".to_vec();
        r.req_body_excerpt = b"same".to_vec();
        // Force a header change so the "no mutation" line doesn't fire.
        r.req_headers_pre = vec![("a".into(), "1".into())];
        r.req_headers = vec![("a".into(), "2".into())];
        let body = render_mutation_diff(&r)
            .iter()
            .map(line_text)
            .collect::<Vec<_>>()
            .join("\n");
        assert!(
            body.contains("byte-identical"),
            "byte-identical body label: {body}"
        );
    }
}