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
//! HTTP レスポンスデコーダー
//!
//! # RFC 非準拠
//!
//! - RFC 9112 Section 2.2: HTTP/1.1 メッセージはオクテット列として解析すべき (SHOULD) だが、
//! 本実装では UTF-8 として強制的に解析している。非 UTF-8 バイト列を含むレスポンスは
//! エラーとして拒否される。
use crate::compression::{CompressionStatus, Decompressor, NoCompression};
use crate::error::Error;
use crate::limits::DecoderLimits;
use crate::response::Response;
use crate::validate::{is_valid_protocol_version, is_valid_reason_phrase, is_valid_status_code};
use super::body::{
BodyDecoder, BodyKind, BodyProgress, TransferEncodingResult, find_line, parse_header_line,
resolve_body_headers_for_response,
};
use super::head::ResponseHead;
use super::phase::DecodePhase;
/// HTTP レスポンスデコーダー (Sans I/O)
///
/// クライアント側でサーバーからのレスポンスをパースする際に使用
///
/// # 型パラメータ
///
/// - `D`: 展開器の型。デフォルトは `NoCompression`(展開なし)。
///
/// # 使い方
///
/// ## 展開なし(既存 API 互換)
///
/// ```rust
/// use shiguredo_http11::ResponseDecoder;
///
/// let mut decoder = ResponseDecoder::new();
/// ```
///
/// ## 展開あり
///
/// ```ignore
/// use shiguredo_http11::ResponseDecoder;
///
/// let mut decoder = ResponseDecoder::with_decompressor(GzipDecompressor::new());
/// ```
#[derive(Debug)]
pub struct ResponseDecoder<D: Decompressor = NoCompression> {
buf: Vec<u8>,
phase: DecodePhase,
start_line: Option<String>,
headers: Vec<(String, String)>,
body_decoder: BodyDecoder,
limits: DecoderLimits,
/// HEAD リクエストへのレスポンスかどうか
expect_no_body: bool,
/// ステータスコード(ヘッダーデコード後に保持)
status_code: u16,
/// decode() 用: デコード済みヘッダー
decoded_head: Option<ResponseHead>,
/// decode() 用: ボディ種別
decoded_body_kind: Option<BodyKind>,
/// decode() 用: デコード済みボディ
decoded_body: Vec<u8>,
/// 展開器
decompressor: D,
/// リクエストメソッド (CONNECT トンネル判定用)
request_method: Option<String>,
}
impl Default for ResponseDecoder<NoCompression> {
fn default() -> Self {
Self::new()
}
}
impl ResponseDecoder<NoCompression> {
/// 新しいデコーダーを作成
pub fn new() -> Self {
Self {
buf: Vec::new(),
phase: DecodePhase::StartLine,
start_line: None,
headers: Vec::new(),
body_decoder: BodyDecoder::new(),
limits: DecoderLimits::default(),
expect_no_body: false,
status_code: 0,
decoded_head: None,
decoded_body_kind: None,
decoded_body: Vec::new(),
decompressor: NoCompression::new(),
request_method: None,
}
}
/// 制限付きでデコーダーを作成
pub fn with_limits(limits: DecoderLimits) -> Self {
Self {
buf: Vec::new(),
phase: DecodePhase::StartLine,
start_line: None,
headers: Vec::new(),
body_decoder: BodyDecoder::new(),
limits,
expect_no_body: false,
status_code: 0,
decoded_head: None,
decoded_body_kind: None,
decoded_body: Vec::new(),
decompressor: NoCompression::new(),
request_method: None,
}
}
}
impl<D: Decompressor> ResponseDecoder<D> {
/// 展開器付きでデコーダーを作成
pub fn with_decompressor(decompressor: D) -> Self {
Self {
buf: Vec::new(),
phase: DecodePhase::StartLine,
start_line: None,
headers: Vec::new(),
body_decoder: BodyDecoder::new(),
limits: DecoderLimits::default(),
expect_no_body: false,
status_code: 0,
decoded_head: None,
decoded_body_kind: None,
decoded_body: Vec::new(),
decompressor,
request_method: None,
}
}
/// 展開器と制限付きでデコーダーを作成
pub fn with_decompressor_and_limits(decompressor: D, limits: DecoderLimits) -> Self {
Self {
buf: Vec::new(),
phase: DecodePhase::StartLine,
start_line: None,
headers: Vec::new(),
body_decoder: BodyDecoder::new(),
limits,
expect_no_body: false,
status_code: 0,
decoded_head: None,
decoded_body_kind: None,
decoded_body: Vec::new(),
decompressor,
request_method: None,
}
}
/// HEAD リクエストへのレスポンスとしてデコード (ボディなし)
pub fn set_expect_no_body(&mut self, expect_no_body: bool) {
self.expect_no_body = expect_no_body;
}
/// リクエストメソッドを設定 (CONNECT トンネル判定用)
///
/// CONNECT メソッドへの 2xx レスポンスはトンネルモードに切り替わる。
/// この場合、ボディは存在せず、バッファ残りデータはトンネルデータとなる。
pub fn set_request_method(&mut self, method: &str) {
self.request_method = Some(method.to_string());
}
/// バッファの残りデータを取り出す (トンネルモード用)
///
/// CONNECT 2xx レスポンス後にトンネルモードに切り替わった場合、
/// このメソッドでヘッダー後のデータを取り出してトンネルに転送する。
///
/// 呼び出し後、バッファは空になる。
pub fn take_remaining(&mut self) -> Vec<u8> {
std::mem::take(&mut self.buf)
}
/// トンネルモードかどうかを判定
///
/// CONNECT 2xx レスポンスの場合、トンネルモードになる。
pub fn is_tunnel(&self) -> bool {
matches!(self.phase, DecodePhase::Tunnel)
}
/// 制限設定を取得
pub fn limits(&self) -> &DecoderLimits {
&self.limits
}
/// バッファにデータを追加
pub fn feed(&mut self, data: &[u8]) -> Result<(), Error> {
let new_size = self.buf.len() + data.len();
if new_size > self.limits.max_buffer_size {
return Err(Error::BufferOverflow {
size: new_size,
limit: self.limits.max_buffer_size,
});
}
self.buf.extend_from_slice(data);
Ok(())
}
/// バッファにデータを追加 (制限チェックなし)
pub fn feed_unchecked(&mut self, data: &[u8]) {
self.buf.extend_from_slice(data);
}
/// バッファの残りデータを取得
pub fn remaining(&self) -> &[u8] {
&self.buf
}
/// デコーダーをリセット
pub fn reset(&mut self) {
self.buf.clear();
self.phase = DecodePhase::StartLine;
self.start_line = None;
self.headers.clear();
self.body_decoder.reset();
self.expect_no_body = false;
self.status_code = 0;
self.decoded_head = None;
self.decoded_body_kind = None;
self.decoded_body.clear();
self.decompressor.reset();
self.request_method = None;
}
/// 接続終了を通知 (close-delimited ボディ用)
///
/// close-delimited ボディを読み取り中に接続が閉じられた場合に呼び出す。
/// これにより、バッファ内の残りデータがボディとして確定し、Complete に遷移する。
///
/// close-delimited 以外の状態で呼び出した場合は何もしない。
pub fn mark_eof(&mut self) {
if matches!(self.phase, DecodePhase::BodyCloseDelimited) {
self.phase = DecodePhase::Complete;
}
}
/// close-delimited ボディを読み取り中かどうかを判定
pub fn is_close_delimited(&self) -> bool {
matches!(self.phase, DecodePhase::BodyCloseDelimited)
}
/// ステータスコードからボディがあるかどうかを判定
fn status_has_body(status_code: u16) -> bool {
// RFC 9112 Section 6.3: 1xx, 204, 304 はボディなし
!((100..200).contains(&status_code) || status_code == 204 || status_code == 304)
}
/// ボディモードを決定
///
/// RFC 9112 Section 6.3 の優先順位に従う:
/// 1. CONNECT 2xx はトンネルモード (Transfer-Encoding/Content-Length は無視)
/// 2. HEAD レスポンス、1xx/204/304 はボディなし (Transfer-Encoding/Content-Length を解析しない)
/// 注: 205 は送信者制約 (RFC 9110) だが、受信者はメッセージ長決定規則に従う
/// 3. Transfer-Encoding がある場合:
/// - chunked が最後 → chunked
/// - chunked がないか最後でない → close-delimited
/// 4. Content-Length がある場合は固定長
/// 5. それ以外は close-delimited (接続が閉じるまでがボディ)
fn determine_body_kind(&self, status_code: u16) -> Result<BodyKind, Error> {
// RFC 9112 Section 6.1: HTTP/1.0 + Transfer-Encoding は framing fault
let version = self
.start_line
.as_ref()
.and_then(|sl| sl.split(' ').next())
.unwrap_or("");
if version == "HTTP/1.0"
&& self
.headers
.iter()
.any(|(name, _)| name.eq_ignore_ascii_case("Transfer-Encoding"))
{
return Err(Error::InvalidData(
"Transfer-Encoding is not defined in HTTP/1.0".to_string(),
));
}
// RFC 9112 Section 6.3: CONNECT メソッドへの 2xx レスポンスは
// トンネルモードに切り替わる。Transfer-Encoding と Content-Length は無視される。
// RFC 9110 Section 9.1: メソッドトークンは case-sensitive
if let Some(ref method) = self.request_method
&& method == "CONNECT"
&& (200..300).contains(&status_code)
{
return Ok(BodyKind::Tunnel);
}
// RFC 9112 Section 6.3: HEAD/1xx/204/304 はボディなし
// 205 は送信者がボディを生成してはならない (RFC 9110 Section 15.3.6) が、
// 受信者はメッセージ長決定規則に従って処理する必要がある
// これらのステータスでは Transfer-Encoding/Content-Length を解析しない
// (不正な TE/CL があってもエラーにしない)
if self.expect_no_body || !Self::status_has_body(status_code) {
return Ok(BodyKind::None);
}
// ボディがある場合のみ TE/CL を解析
let (te_result, content_length) = resolve_body_headers_for_response(&self.headers)?;
match te_result {
TransferEncodingResult::Chunked => return Ok(BodyKind::Chunked),
TransferEncodingResult::Other => return Ok(BodyKind::CloseDelimited),
TransferEncodingResult::None => {}
}
if let Some(len) = content_length {
if len > self.limits.max_body_size {
return Err(Error::BodyTooLarge {
size: len,
limit: self.limits.max_body_size,
});
}
return Ok(BodyKind::ContentLength(len));
}
// RFC 9112: TE も CL もない場合は close-delimited
// 接続が閉じられるまでをボディとして扱う
Ok(BodyKind::CloseDelimited)
}
/// ヘッダーをデコード
///
/// ヘッダーが完了したら `Some((ResponseHead, BodyKind))` を返す
/// データ不足の場合は `None` を返す
/// 既にヘッダーデコード済みの場合はエラー
pub fn decode_headers(&mut self) -> Result<Option<(ResponseHead, BodyKind)>, Error> {
loop {
match &self.phase {
DecodePhase::StartLine => {
if let Some(pos) = find_line(&self.buf) {
let line = String::from_utf8(self.buf[..pos].to_vec())
.map_err(|e| Error::InvalidData(format!("invalid UTF-8: {e}")))?;
self.buf.drain(..pos + 2);
// CR/LF チェック (埋め込まれた改行を拒否)
if line.contains('\r') || line.contains('\n') {
return Err(Error::InvalidData(
"invalid status line: contains CR/LF".to_string(),
));
}
// Parse: VERSION SP STATUS-CODE SP REASON-PHRASE CRLF
let parts: Vec<&str> = line.splitn(3, ' ').collect();
if parts.len() < 2 {
return Err(Error::InvalidData(format!(
"invalid status line: {}",
line
)));
}
// プロトコルバージョンの検証
if !is_valid_protocol_version(parts[0]) {
return Err(Error::InvalidData(
"invalid status line: invalid protocol version".to_string(),
));
}
// ステータスコードの検証 (RFC 9110 Section 15)
let status_code: u16 = parts[1].parse().map_err(|_| {
Error::InvalidData(format!(
"invalid status line: invalid status code: {}",
parts[1]
))
})?;
if !is_valid_status_code(status_code) {
return Err(Error::InvalidData(format!(
"invalid status line: status code out of range: {}",
status_code
)));
}
// reason-phrase の検証 (RFC 9112 Section 4)
if let Some(reason) = parts.get(2)
&& !is_valid_reason_phrase(reason)
{
return Err(Error::InvalidData(
"invalid status line: invalid reason-phrase".to_string(),
));
}
self.start_line = Some(line);
self.phase = DecodePhase::Headers;
} else {
return Ok(None);
}
}
DecodePhase::Headers => {
if let Some(pos) = find_line(&self.buf) {
if pos == 0 {
// Empty line - end of headers
self.buf.drain(..2);
// ステータスコードを取得
let start_line = self.start_line.as_ref().ok_or_else(|| {
Error::InvalidData("missing status line".to_string())
})?;
let parts: Vec<&str> = start_line.splitn(3, ' ').collect();
let status_code: u16 = parts[1].parse().map_err(|_| {
Error::InvalidData(format!("invalid status code: {}", parts[1]))
})?;
self.status_code = status_code;
let body_kind = self.determine_body_kind(status_code)?;
// ヘッダー完了、ボディフェーズに遷移
match body_kind {
BodyKind::ContentLength(len) => {
if len > 0 {
self.phase =
DecodePhase::BodyContentLength { remaining: len };
} else {
self.phase = DecodePhase::Complete;
}
}
BodyKind::Chunked => {
self.phase = DecodePhase::BodyChunkedSize;
}
BodyKind::CloseDelimited => {
self.phase = DecodePhase::BodyCloseDelimited;
}
BodyKind::None => {
self.phase = DecodePhase::Complete;
}
BodyKind::Tunnel => {
self.phase = DecodePhase::Tunnel;
}
}
// ResponseHead を構築
let start_line = self.start_line.take().unwrap();
let parts: Vec<&str> = start_line.splitn(3, ' ').collect();
let head = ResponseHead {
version: parts[0].to_string(),
status_code,
reason_phrase: parts.get(2).unwrap_or(&"").to_string(),
headers: std::mem::take(&mut self.headers),
};
return Ok(Some((head, body_kind)));
} else {
// Check header line size limit
if pos > self.limits.max_header_line_size {
return Err(Error::HeaderLineTooLong {
size: pos,
limit: self.limits.max_header_line_size,
});
}
// Check header count limit
if self.headers.len() >= self.limits.max_headers_count {
return Err(Error::TooManyHeaders {
count: self.headers.len() + 1,
limit: self.limits.max_headers_count,
});
}
let line = String::from_utf8(self.buf[..pos].to_vec())
.map_err(|e| Error::InvalidData(format!("invalid UTF-8: {e}")))?;
self.buf.drain(..pos + 2);
let (name, value) = parse_header_line(&line)?;
self.headers.push((name, value));
}
} else {
return Ok(None);
}
}
DecodePhase::Complete => {
// 完了状態から次のメッセージへ遷移
self.phase = DecodePhase::StartLine;
self.start_line = None;
self.headers.clear();
self.body_decoder.reset();
self.expect_no_body = false;
self.status_code = 0;
continue;
}
DecodePhase::Tunnel => {
return Err(Error::InvalidData(
"decode_headers cannot be used in tunnel mode".to_string(),
));
}
_ => {
return Err(Error::InvalidData(
"decode_headers called during body decoding".to_string(),
));
}
}
}
}
/// 利用可能なボディデータを覗く(ゼロコピー)
///
/// `decode_headers()` 成功後に呼ぶ
/// データがある場合はスライスを返す
/// ボディがない場合や完了済みの場合は `None` を返す
pub fn peek_body(&self) -> Option<&[u8]> {
self.body_decoder.peek_body(&self.buf, &self.phase)
}
/// ボディデータを展開して取得
///
/// `decode_headers()` 成功後に呼ぶ。
/// 利用可能なボディデータを展開して output に書き込む。
///
/// # 引数
/// - `output`: 展開データを書き込む出力バッファ
///
/// # 戻り値
/// - `Ok(Some(status))`: 展開成功。`status.produced()` バイトが output に書き込まれた。
/// `status.consumed()` バイトを `consume_body()` で消費する必要がある。
/// - `Ok(None)`: 利用可能なボディデータがない
/// - `Err(e)`: 展開エラー
///
/// # 使い方
///
/// ```ignore
/// let mut output = vec![0u8; 8192];
/// while let Some(status) = decoder.peek_body_decompressed(&mut output)? {
/// // output[..status.produced()] に展開済みデータ
/// process(&output[..status.produced()]);
/// decoder.consume_body(status.consumed())?;
/// }
/// ```
pub fn peek_body_decompressed(
&mut self,
output: &mut [u8],
) -> Result<Option<CompressionStatus>, Error> {
let input = match self.body_decoder.peek_body(&self.buf, &self.phase) {
Some(data) if !data.is_empty() => data,
_ => return Ok(None),
};
let status = self.decompressor.decompress(input, output)?;
Ok(Some(status))
}
/// 利用可能なボディデータのバイト数を取得
fn available_body_len(&self) -> usize {
match &self.phase {
DecodePhase::BodyContentLength { remaining } => self.buf.len().min(*remaining),
DecodePhase::BodyChunkedData { remaining } => self.buf.len().min(*remaining),
DecodePhase::BodyCloseDelimited => self.buf.len(),
_ => 0,
}
}
/// ボディデータを消費
///
/// `peek_body()` で取得したデータを処理した後に呼ぶ
/// `len` は消費するバイト数 (1 以上)
pub fn consume_body(&mut self, len: usize) -> Result<BodyProgress, Error> {
if len == 0 {
return Err(Error::InvalidData(
"consume_body(0) is not allowed, use progress() instead".to_string(),
));
}
self.body_decoder
.consume_body(&mut self.buf, &mut self.phase, len, &self.limits)
}
/// 状態機械を進める (ボディデータは消費しない)
///
/// Chunked エンコーディングの場合、チャンクサイズ行のパースや
/// 終端チャンクの処理を行う。
pub fn progress(&mut self) -> Result<BodyProgress, Error> {
self.body_decoder
.consume_body(&mut self.buf, &mut self.phase, 0, &self.limits)
}
/// レスポンス全体を一括でデコード
///
/// ストリーミング API (`decode_headers()` / `peek_body()` / `consume_body()`) を
/// 内部で使用して、レスポンス全体をデコードする。
///
/// データ不足の場合は `None` を返す。
/// ストリーミング API と混在使用するとエラーを返す。
///
/// ## close-delimited ボディの場合
///
/// `BodyKind::CloseDelimited` の場合、接続が閉じられるまでがボディとなる。
/// `decode()` を使う場合は、接続終了後に `mark_eof()` を呼んでから
/// 再度 `decode()` を呼ぶ必要がある。
pub fn decode(&mut self) -> Result<Option<Response>, Error> {
// ヘッダーがまだデコードされていない場合はデコード
if self.decoded_head.is_none() {
match self.phase {
DecodePhase::StartLine | DecodePhase::Headers => match self.decode_headers()? {
Some((head, body_kind)) => {
self.decoded_head = Some(head);
self.decoded_body_kind = Some(body_kind);
}
None => return Ok(None),
},
_ => {
return Err(Error::InvalidData(
"decode cannot be mixed with streaming API".to_string(),
));
}
}
}
// ボディを読む
let body_kind = *self.decoded_body_kind.as_ref().unwrap();
match body_kind {
BodyKind::Tunnel => {
return Err(Error::InvalidData(
"decode() cannot be used in tunnel mode, use take_remaining() instead"
.to_string(),
));
}
BodyKind::ContentLength(_) | BodyKind::Chunked => loop {
// 直接バッファから利用可能なデータ長を取得(コピーなし)
let available = self.available_body_len();
if available > 0 {
// バッファから直接コピー
self.decoded_body.extend_from_slice(&self.buf[..available]);
match self.consume_body(available)? {
BodyProgress::Complete { .. } => break,
BodyProgress::Continue => continue,
}
}
// データがない場合、状態機械を進める
match self.progress()? {
BodyProgress::Complete { .. } => break,
BodyProgress::Continue => {
// 状態遷移後にデータが利用可能になったか確認
if self.available_body_len() > 0 {
continue;
}
// データ不足
return Ok(None);
}
}
},
BodyKind::CloseDelimited => {
// close-delimited: バッファにあるデータを読み込み、mark_eof() を待つ
let available = self.available_body_len();
if available > 0 {
// max_body_size チェック (コピー前に行う)
// checked_add でオーバーフローを検出し、オーバーフロー時も BodyTooLarge を返す
let new_size = self.decoded_body.len().checked_add(available).ok_or(
Error::BodyTooLarge {
size: usize::MAX,
limit: self.limits.max_body_size,
},
)?;
if new_size > self.limits.max_body_size {
return Err(Error::BodyTooLarge {
size: new_size,
limit: self.limits.max_body_size,
});
}
self.decoded_body.extend_from_slice(&self.buf[..available]);
self.consume_body(available)?;
}
// mark_eof() が呼ばれて Complete になったか確認
if !matches!(self.phase, DecodePhase::Complete) {
// まだ EOF でないのでデータ不足
return Ok(None);
}
}
BodyKind::None => {}
}
// Response を構築
let head = self.decoded_head.take().unwrap();
let body = std::mem::take(&mut self.decoded_body);
// Keep-Alive 対応: 次のレスポンスのために状態をリセット
self.phase = DecodePhase::StartLine;
self.decoded_body_kind = None;
self.body_decoder.reset();
self.expect_no_body = false;
self.status_code = 0;
Ok(Some(Response {
version: head.version,
status_code: head.status_code,
reason_phrase: head.reason_phrase,
headers: head.headers,
body,
omit_body: false,
}))
}
}