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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
//! HTTP response representation.
use std::collections::HashMap;
use std::fmt;
use std::time::Duration;
/// The HTTP version actually used in a response.
///
/// Unlike [`HttpVersion`](crate::HttpVersion) which represents the *requested*
/// protocol version, this enum represents the version that was actually
/// negotiated and used for the transfer.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ResponseHttpVersion {
/// HTTP version unknown or not applicable (e.g., non-HTTP protocols).
#[default]
Unknown,
/// HTTP/1.0
Http10,
/// HTTP/1.1
Http11,
/// HTTP/2
Http2,
/// HTTP/3
Http3,
}
impl fmt::Display for ResponseHttpVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unknown => write!(f, "0"),
Self::Http10 => write!(f, "1.0"),
Self::Http11 => write!(f, "1.1"),
Self::Http2 => write!(f, "2"),
Self::Http3 => write!(f, "3"),
}
}
}
/// Transfer timing and metadata information.
///
/// Timing fields follow curl's conventions:
/// - `time_namelookup`: DNS resolution completed
/// - `time_connect`: TCP connection established
/// - `time_appconnect`: TLS handshake completed (HTTPS only)
/// - `time_pretransfer`: Ready to send request
/// - `time_starttransfer`: First response byte received
/// - `time_total`: Entire transfer completed
#[derive(Debug, Clone, Default)]
pub struct TransferInfo {
/// Time from start until DNS name resolution completed.
pub time_namelookup: Duration,
/// Time from start until TCP connection was established.
pub time_connect: Duration,
/// Time from start until TLS/SSL handshake completed (HTTPS only).
pub time_appconnect: Duration,
/// Time from start until the request is ready to be sent.
pub time_pretransfer: Duration,
/// Time from start until the first response byte was received.
pub time_starttransfer: Duration,
/// Total time for the entire transfer.
pub time_total: Duration,
/// Number of redirects followed.
pub num_redirects: u32,
/// Average download speed in bytes per second.
pub speed_download: f64,
/// Average upload speed in bytes per second.
pub speed_upload: f64,
/// Total bytes uploaded.
pub size_upload: u64,
/// Number of retries performed.
pub num_retries: u32,
/// The effective HTTP method used for the transfer (e.g., "GET", "POST").
pub effective_method: String,
/// The Referer header value used in the last request (for `%{referer}` write-out).
pub referer: String,
/// Local IP address of the connection.
pub local_ip: String,
/// Local port of the connection.
pub local_port: u16,
/// Remote IP address of the connection.
pub remote_ip: String,
/// Remote port of the connection.
pub remote_port: u16,
/// TLS peer certificate chain in DER-encoded format.
pub certs_der: Vec<Vec<u8>>,
}
/// An HTTP response with status, headers, and body.
#[derive(Debug, Clone)]
pub struct Response {
/// HTTP status code (e.g., 200, 404).
status: u16,
/// The HTTP reason phrase from the status line (e.g., "OK", "Not Found").
/// Preserves the server's original text. `None` if no reason was sent.
status_reason: Option<String>,
/// The HTTP version used in the response.
http_version: ResponseHttpVersion,
/// Response headers (lowercase keys for lookup).
headers: HashMap<String, String>,
/// Original header names preserving server casing (lowercase → original).
header_original_names: HashMap<String, String>,
/// Headers in wire order with original casing. Preserves duplicates.
headers_ordered: Vec<(String, String)>,
/// Whether the response used CRLF (`true`) or bare LF (`false`) line endings.
uses_crlf: bool,
/// Trailer headers from chunked transfer encoding.
trailers: HashMap<String, String>,
/// Raw trailer bytes as received from the wire (for output).
/// Includes each trailer line with its original line endings.
raw_trailers: Vec<u8>,
/// Response body bytes.
body: Vec<u8>,
/// The effective URL after any redirects.
effective_url: String,
/// Transfer timing and metadata.
info: TransferInfo,
/// HTTP/2 server-pushed responses received during this transfer.
pushed_responses: Vec<PushedResponse>,
/// Intermediate redirect responses (for `-L --include` output).
redirect_responses: Vec<Self>,
/// Error message from body reading (e.g., bad chunked encoding).
/// When set, the response is partial — headers are valid but the body
/// may be incomplete. Used to output partial data on error (curl compat).
body_error: Option<String>,
/// Raw header bytes as received from the wire (for `--include` output).
/// Includes the status line and all headers with original line endings.
/// Does NOT include the trailing blank line separator.
raw_headers: Option<Vec<u8>>,
/// The HTTP status code from a CONNECT tunnel response (for `%{http_connect}`).
/// 0 when no CONNECT tunnel was used.
connect_code: u16,
/// Pre-computed total header size in bytes (for `%{size_header}` when
/// `--suppress-connect-headers` is used). When set, this overrides the
/// dynamically computed size. 0 means "not set, compute dynamically".
total_header_size: usize,
}
/// An HTTP/2 server-pushed response.
///
/// Represents a resource that the server proactively sent via HTTP/2 server push
/// (`PUSH_PROMISE` frame). Contains the promised request URL and the pushed response.
#[derive(Debug, Clone)]
pub struct PushedResponse {
/// The URL of the pushed resource (from the `PUSH_PROMISE` request headers).
pub url: String,
/// HTTP status code of the pushed response.
pub status: u16,
/// Response headers.
pub headers: HashMap<String, String>,
/// Response body bytes.
pub body: Vec<u8>,
}
impl Response {
/// Create a new response.
#[must_use]
pub fn new(
status: u16,
headers: HashMap<String, String>,
body: Vec<u8>,
effective_url: String,
) -> Self {
Self {
status,
status_reason: None,
http_version: ResponseHttpVersion::default(),
headers,
header_original_names: HashMap::new(),
headers_ordered: Vec::new(),
uses_crlf: true,
trailers: HashMap::new(),
raw_trailers: Vec::new(),
body,
effective_url,
info: TransferInfo::default(),
pushed_responses: Vec::new(),
redirect_responses: Vec::new(),
body_error: None,
raw_headers: None,
connect_code: 0,
total_header_size: 0,
}
}
/// Create a new response with transfer info.
#[must_use]
pub fn with_info(
status: u16,
headers: HashMap<String, String>,
body: Vec<u8>,
effective_url: String,
info: TransferInfo,
) -> Self {
Self {
status,
status_reason: None,
http_version: ResponseHttpVersion::default(),
headers,
header_original_names: HashMap::new(),
headers_ordered: Vec::new(),
uses_crlf: true,
trailers: HashMap::new(),
raw_trailers: Vec::new(),
body,
effective_url,
info,
pushed_responses: Vec::new(),
redirect_responses: Vec::new(),
body_error: None,
raw_headers: None,
connect_code: 0,
total_header_size: 0,
}
}
/// Create a new response with pre-set raw header bytes.
///
/// Used for CONNECT proxy responses that need to be included in `--include` output.
#[must_use]
pub fn with_raw_headers(
status: u16,
headers: HashMap<String, String>,
body: Vec<u8>,
effective_url: String,
raw_headers: Vec<u8>,
) -> Self {
Self {
status,
status_reason: None,
http_version: ResponseHttpVersion::default(),
headers,
header_original_names: HashMap::new(),
headers_ordered: Vec::new(),
uses_crlf: true,
trailers: HashMap::new(),
raw_trailers: Vec::new(),
body,
effective_url,
info: TransferInfo::default(),
pushed_responses: Vec::new(),
redirect_responses: Vec::new(),
body_error: None,
raw_headers: Some(raw_headers),
connect_code: 0,
total_header_size: 0,
}
}
/// Set the original header name casing map (lowercase → original).
pub fn set_header_original_names(&mut self, names: HashMap<String, String>) {
self.header_original_names = names;
}
/// Returns the original header names map (lowercase → original casing).
#[must_use]
pub const fn header_original_names(&self) -> &HashMap<String, String> {
&self.header_original_names
}
/// Set headers in wire order with original casing (preserves duplicates).
pub fn set_headers_ordered(&mut self, ordered: Vec<(String, String)>) {
self.headers_ordered = ordered;
}
/// Returns headers in wire order with original casing.
///
/// Empty if not set (e.g., non-HTTP protocols).
#[must_use]
pub fn headers_ordered(&self) -> &[(String, String)] {
&self.headers_ordered
}
/// Whether the response used CRLF line endings (vs bare LF).
#[must_use]
pub const fn uses_crlf(&self) -> bool {
self.uses_crlf
}
/// Set whether the response used CRLF line endings.
pub const fn set_uses_crlf(&mut self, uses_crlf: bool) {
self.uses_crlf = uses_crlf;
}
/// Set trailer headers on this response.
pub fn set_trailers(&mut self, trailers: HashMap<String, String>) {
self.trailers = trailers;
}
/// Set raw trailer bytes as received from the wire.
pub fn set_raw_trailers(&mut self, raw: Vec<u8>) {
self.raw_trailers = raw;
}
/// Returns raw trailer bytes if available.
#[must_use]
pub fn raw_trailers(&self) -> &[u8] {
&self.raw_trailers
}
/// Set raw header bytes as received from the wire.
pub fn set_raw_headers(&mut self, raw: Vec<u8>) {
self.raw_headers = Some(raw);
}
/// Returns raw header bytes if available.
#[must_use]
pub fn raw_headers(&self) -> Option<&[u8]> {
self.raw_headers.as_deref()
}
/// Returns the HTTP status code.
#[must_use]
pub const fn status(&self) -> u16 {
self.status
}
/// Returns the HTTP reason phrase from the status line (e.g., "OK").
#[must_use]
pub fn status_reason(&self) -> Option<&str> {
self.status_reason.as_deref()
}
/// Set the HTTP reason phrase from the status line.
pub fn set_status_reason(&mut self, reason: Option<String>) {
self.status_reason = reason;
}
/// Returns the HTTP version used in the response.
#[must_use]
pub const fn http_version(&self) -> ResponseHttpVersion {
self.http_version
}
/// Set the HTTP version used in the response.
pub const fn set_http_version(&mut self, version: ResponseHttpVersion) {
self.http_version = version;
}
/// Returns the response headers.
#[must_use]
pub const fn headers(&self) -> &HashMap<String, String> {
&self.headers
}
/// Returns a specific header value (case-insensitive lookup).
///
/// Headers are stored lowercase, so this avoids allocation when the
/// caller passes a lowercase name (common case).
#[must_use]
pub fn header(&self, name: &str) -> Option<&str> {
// Fast path: try direct lookup first (works when name is already lowercase)
if let Some(v) = self.headers.get(name) {
return Some(v.as_str());
}
// Slow path: lowercase and retry (only allocates if direct lookup missed)
let lower = name.to_lowercase();
if lower == name {
None
} else {
self.headers.get(&lower).map(String::as_str)
}
}
/// Returns the response body as bytes.
#[must_use]
pub fn body(&self) -> &[u8] {
&self.body
}
/// Returns the response body as a UTF-8 string, if valid.
///
/// # Errors
///
/// Returns [`Error::Http`](crate::Error::Http) if the body is not valid UTF-8.
pub fn body_str(&self) -> Result<&str, crate::Error> {
std::str::from_utf8(&self.body)
.map_err(|e| crate::Error::Http(format!("body is not valid UTF-8: {e}")))
}
/// Returns the effective URL (after redirects).
#[must_use]
pub fn effective_url(&self) -> &str {
&self.effective_url
}
/// Returns true if this is a redirect response (3xx with non-empty Location header).
///
/// A blank or whitespace-only `Location` header is treated as "no redirect",
/// matching curl's behavior and avoiding infinite redirect loops.
#[must_use]
pub fn is_redirect(&self) -> bool {
matches!(self.status, 301 | 302 | 303 | 307 | 308)
&& self.headers.get("location").is_some_and(|v| !v.trim().is_empty())
}
/// Returns the Content-Type header value, if present.
#[must_use]
pub fn content_type(&self) -> Option<&str> {
self.header("content-type")
}
/// Returns the trailer headers from chunked transfer encoding.
#[must_use]
pub const fn trailers(&self) -> &HashMap<String, String> {
&self.trailers
}
/// Returns a specific trailer header value (case-insensitive lookup).
#[must_use]
pub fn trailer(&self, name: &str) -> Option<&str> {
let lower = name.to_lowercase();
self.trailers.get(&lower).map(String::as_str)
}
/// Returns the size of the response body in bytes.
#[must_use]
pub fn size_download(&self) -> usize {
self.body.len()
}
/// Returns the transfer timing and metadata.
#[must_use]
pub const fn transfer_info(&self) -> &TransferInfo {
&self.info
}
/// Set the transfer info on this response.
pub fn set_transfer_info(&mut self, info: TransferInfo) {
self.info = info;
}
/// Returns HTTP/2 server-pushed responses received during this transfer.
#[must_use]
pub fn pushed_responses(&self) -> &[PushedResponse] {
&self.pushed_responses
}
/// Set pushed responses on this response.
pub fn set_pushed_responses(&mut self, pushed: Vec<PushedResponse>) {
self.pushed_responses = pushed;
}
/// Returns intermediate redirect responses in the chain.
#[must_use]
pub fn redirect_responses(&self) -> &[Self] {
&self.redirect_responses
}
/// Add an intermediate redirect response to the chain.
pub fn push_redirect_response(&mut self, resp: Self) {
self.redirect_responses.push(resp);
}
/// Set intermediate redirect responses.
pub fn set_redirect_responses(&mut self, resps: Vec<Self>) {
self.redirect_responses = resps;
}
/// Remove CONNECT tunnel responses from the redirect chain.
///
/// Used with `--suppress-connect-headers` to hide CONNECT response
/// headers from `--include` and `--dump-header` output while keeping
/// the `connect_code` for `%{http_connect}`.
pub fn suppress_connect_headers(&mut self) {
// CONNECT responses are added as redirect_responses with empty
// parsed headers (only raw_headers are set). Keep actual redirect
// responses (from -L) which have parsed headers.
self.redirect_responses.retain(|r| !r.headers.is_empty());
}
/// Returns the body error message, if any.
///
/// When set, the response is partial — headers are valid but the body
/// may be incomplete. The caller should output available data and then
/// return the appropriate error exit code.
#[must_use]
pub fn body_error(&self) -> Option<&str> {
self.body_error.as_deref()
}
/// Set a body error message (for partial responses).
pub fn set_body_error(&mut self, error: Option<String>) {
self.body_error = error;
}
/// Replace the response body bytes.
///
/// Used for decompression and other body transformations that should
/// preserve all other response metadata (headers, status, `raw_headers`, etc.).
pub fn set_body(&mut self, body: Vec<u8>) {
self.body = body;
}
/// Prepend data before the existing body.
pub fn prepend_body(&mut self, prefix: &[u8]) {
let mut new_body = Vec::with_capacity(prefix.len() + self.body.len());
new_body.extend_from_slice(prefix);
new_body.extend_from_slice(&self.body);
self.body = new_body;
}
/// Returns the HTTP status code from the CONNECT tunnel response.
///
/// Returns 0 when no CONNECT tunnel was used. This maps to curl's
/// `%{http_connect}` write-out variable.
#[must_use]
pub const fn connect_code(&self) -> u16 {
self.connect_code
}
/// Set the HTTP CONNECT tunnel response status code.
pub const fn set_connect_code(&mut self, code: u16) {
self.connect_code = code;
}
/// Returns the pre-computed total header size, if set.
///
/// When non-zero, this overrides the dynamically computed `%{size_header}`.
/// Used with `--suppress-connect-headers` to preserve the total byte count
/// even after CONNECT responses are removed from the redirect chain.
#[must_use]
pub const fn total_header_size(&self) -> usize {
self.total_header_size
}
/// Set the pre-computed total header size.
pub const fn set_total_header_size(&mut self, size: usize) {
self.total_header_size = size;
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, unused_results)]
mod tests {
use super::*;
#[test]
fn response_status() {
let resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
assert_eq!(resp.status(), 200);
}
#[test]
fn response_header_case_insensitive() {
let mut headers = HashMap::new();
headers.insert("content-type".to_string(), "text/html".to_string());
let resp = Response::new(200, headers, Vec::new(), String::new());
assert_eq!(resp.header("Content-Type"), Some("text/html"));
}
#[test]
fn response_body_str() {
let body = b"hello world".to_vec();
let resp = Response::new(200, HashMap::new(), body, String::new());
assert_eq!(resp.body_str().unwrap(), "hello world");
}
#[test]
fn response_body_str_invalid_utf8() {
let body = vec![0xFF, 0xFE];
let resp = Response::new(200, HashMap::new(), body, String::new());
assert!(resp.body_str().is_err());
}
#[test]
fn response_trailers_empty_by_default() {
let resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
assert!(resp.trailers().is_empty());
assert!(resp.trailer("X-Foo").is_none());
}
#[test]
fn response_trailers_set_and_get() {
let mut resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
let mut trailers = HashMap::new();
trailers.insert("x-checksum".to_string(), "abc123".to_string());
trailers.insert("x-timestamp".to_string(), "1234567890".to_string());
resp.set_trailers(trailers);
assert_eq!(resp.trailer("X-Checksum"), Some("abc123"));
assert_eq!(resp.trailer("X-Timestamp"), Some("1234567890"));
assert_eq!(resp.trailers().len(), 2);
}
#[test]
fn response_pushed_responses_empty_by_default() {
let resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
assert!(resp.pushed_responses().is_empty());
}
#[test]
fn response_pushed_responses_set_and_get() {
let mut resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
let pushed = vec![PushedResponse {
url: "https://example.com/style.css".to_string(),
status: 200,
headers: HashMap::new(),
body: b"body{color:red}".to_vec(),
}];
resp.set_pushed_responses(pushed);
assert_eq!(resp.pushed_responses().len(), 1);
assert_eq!(resp.pushed_responses()[0].url, "https://example.com/style.css");
assert_eq!(resp.pushed_responses()[0].status, 200);
assert_eq!(resp.pushed_responses()[0].body, b"body{color:red}");
}
#[test]
fn response_trailer_case_insensitive() {
let mut resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
let mut trailers = HashMap::new();
trailers.insert("x-custom".to_string(), "value".to_string());
resp.set_trailers(trailers);
assert_eq!(resp.trailer("X-Custom"), Some("value"));
assert_eq!(resp.trailer("x-custom"), Some("value"));
assert_eq!(resp.trailer("X-CUSTOM"), Some("value"));
}
#[test]
fn response_http_version_default() {
let resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
assert_eq!(resp.http_version(), ResponseHttpVersion::Unknown);
}
#[test]
fn response_http_version_set_and_get() {
let mut resp = Response::new(200, HashMap::new(), Vec::new(), String::new());
resp.set_http_version(ResponseHttpVersion::Http2);
assert_eq!(resp.http_version(), ResponseHttpVersion::Http2);
}
#[test]
fn response_http_version_display() {
assert_eq!(ResponseHttpVersion::Unknown.to_string(), "0");
assert_eq!(ResponseHttpVersion::Http10.to_string(), "1.0");
assert_eq!(ResponseHttpVersion::Http11.to_string(), "1.1");
assert_eq!(ResponseHttpVersion::Http2.to_string(), "2");
assert_eq!(ResponseHttpVersion::Http3.to_string(), "3");
}
#[test]
fn header_lookup_fast_path() {
let mut headers = HashMap::new();
headers.insert("content-type".to_string(), "text/html".to_string());
let resp = Response::new(200, headers, Vec::new(), String::new());
// Fast path: lowercase name hits directly
assert_eq!(resp.header("content-type"), Some("text/html"));
// Slow path: mixed case triggers lowercase conversion
assert_eq!(resp.header("Content-Type"), Some("text/html"));
// Miss: both paths return None
assert_eq!(resp.header("x-missing"), None);
assert_eq!(resp.header("X-Missing"), None);
}
#[test]
fn is_redirect_with_valid_location() {
let mut headers = HashMap::new();
headers.insert("location".to_string(), "http://example.com/new".to_string());
let resp = Response::new(302, headers, Vec::new(), String::new());
assert!(resp.is_redirect());
}
#[test]
fn is_redirect_with_empty_location() {
let mut headers = HashMap::new();
headers.insert("location".to_string(), String::new());
let resp = Response::new(302, headers, Vec::new(), String::new());
assert!(!resp.is_redirect(), "empty Location should not be treated as a redirect");
}
#[test]
fn is_redirect_with_whitespace_only_location() {
let mut headers = HashMap::new();
headers.insert("location".to_string(), " \t ".to_string());
let resp = Response::new(301, headers, Vec::new(), String::new());
assert!(
!resp.is_redirect(),
"whitespace-only Location should not be treated as a redirect"
);
}
#[test]
fn is_redirect_without_location_header() {
let resp = Response::new(301, HashMap::new(), Vec::new(), String::new());
assert!(!resp.is_redirect(), "redirect status without Location header should not redirect");
}
#[test]
fn is_redirect_non_redirect_status() {
let mut headers = HashMap::new();
headers.insert("location".to_string(), "http://example.com/new".to_string());
let resp = Response::new(200, headers, Vec::new(), String::new());
assert!(!resp.is_redirect(), "200 with Location should not be treated as a redirect");
}
}