From be9bc237f29d58778f426cdc456066bb4c5b8b5a Mon Sep 17 00:00:00 2001
From: Pat Hickey
Date: Tue, 25 Nov 2025 17:20:41 -0800
Subject: [PATCH] NFC: simplify internals of http::response::try_from_incoming
---
src/http/response.rs | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/http/response.rs b/src/http/response.rs
index d0af77e..2ab8d87 100644
--- a/src/http/response.rs
+++ b/src/http/response.rs
@@ -2,7 +2,7 @@ use http::StatusCode;
use wasip2::http::types::IncomingResponse;
use crate::http::body::{Body, BodyHint};
-use crate::http::error::{Context, Error};
+use crate::http::error::Error;
use crate::http::fields::{HeaderMap, header_map_from_wasi};
pub use http::response::{Builder, Response};
@@ -22,10 +22,17 @@ pub(crate) fn try_from_incoming(incoming: IncomingResponse) -> Result` or
+ // `TryInto`. Since the `Builder::header` method is never
+ // used, we know `Builder::headers_mut` will never give the None case, nor
+ // will `Builder::body` give the error case. So, rather than treat those
+ // as control flow, we unwrap if this invariant is ever broken because
+ // that would only be possible due to some unrecoverable bug in wstd,
+ // rather than incorrect use or invalid input.
+ *builder.headers_mut().expect("builder has not errored") = headers;
+ Ok(builder
+ .body(body)
+ .expect("response builder should not error"))
}