From 3debec139367947a921bed3a1c633220347d6e61 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 12 Dec 2025 12:55:57 -0500 Subject: [PATCH] Simplify some path resolving logic --- .../src/wasm_host/wit/since_v0_8_0.rs | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs b/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs index 9c807d1376b09ecee7b9e8b0444c685e71ecae8d..a95ad0a8ac6bac08bfa3ad1c0e53e72e64cdef62 100644 --- a/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs +++ b/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs @@ -1309,24 +1309,17 @@ impl llm_provider::Host for WasmState { .map_err(|e| anyhow::anyhow!("Failed to read request: {}", e))?; } - let callback_url = if let Some(path_start) = request_line.find(' ') { - if let Some(path_end) = request_line[path_start + 1..].find(' ') { - let path = &request_line[path_start + 1..path_start + 1 + path_end]; - if path.starts_with(&callback_path) - || path.starts_with(&format!( - "/{}", - callback_path.trim_start_matches('/') - )) - { - format!("http://localhost:{}{}", port, path) - } else { - return Err(anyhow::anyhow!("Unexpected callback path: {}", path)); - } - } else { - return Err(anyhow::anyhow!("Malformed HTTP request")); - } + let path = request_line + .split_whitespace() + .nth(1) + .ok_or_else(|| anyhow::anyhow!("Malformed HTTP request"))?; + + let callback_url = if path.starts_with(&callback_path) + || path.starts_with(&format!("/{}", callback_path.trim_start_matches('/'))) + { + format!("http://localhost:{}{}", port, path) } else { - return Err(anyhow::anyhow!("Malformed HTTP request")); + return Err(anyhow::anyhow!("Unexpected callback path: {}", path)); }; let response = format!(