Skip to content

Commit 1b2d5d1

Browse files
authored
Merge pull request #172 from hyperware-ai/hf/dont-set-response-body
hyperapp: remove set_response_body
2 parents ad352be + b390253 commit 1b2d5d1

File tree

2 files changed

+2
-42
lines changed

2 files changed

+2
-42
lines changed

src/http/server.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,16 +1080,6 @@ impl HttpServer {
10801080

10811081
/// Send an HTTP response to an incoming HTTP request ([`HttpServerRequest::Http`]).
10821082
pub fn send_response(status: StatusCode, headers: Option<HashMap<String, String>>, body: Vec<u8>) {
1083-
// Check if there's a manual body override in the HTTP context
1084-
let final_body = crate::hyperapp::APP_HELPERS.with(|helpers| {
1085-
helpers
1086-
.borrow()
1087-
.current_http_context
1088-
.as_ref()
1089-
.and_then(|ctx| ctx.response_body.clone())
1090-
.unwrap_or(body) // Use override if present, otherwise use the parameter
1091-
});
1092-
10931083
KiResponse::new()
10941084
.body(
10951085
serde_json::to_vec(&HttpResponse {
@@ -1098,7 +1088,7 @@ pub fn send_response(status: StatusCode, headers: Option<HashMap<String, String>
10981088
})
10991089
.unwrap(),
11001090
)
1101-
.blob_bytes(final_body)
1091+
.blob_bytes(body)
11021092
.send()
11031093
.unwrap()
11041094
}

src/hyperapp.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub struct HttpRequestContext {
4343
pub request: IncomingHttpRequest,
4444
pub response_headers: HashMap<String, String>,
4545
pub response_status: http::StatusCode,
46-
pub response_body: Option<Vec<u8>>,
4746
}
4847

4948
pub struct AppContext {
@@ -144,15 +143,6 @@ pub fn set_response_status(status: http::StatusCode) {
144143
})
145144
}
146145

147-
// Set the HTTP response body directly (bypasses Result serialization)
148-
pub fn set_response_body(body: Vec<u8>) {
149-
APP_HELPERS.with(|helpers| {
150-
if let Some(ctx) = &mut helpers.borrow_mut().current_http_context {
151-
ctx.response_body = Some(body);
152-
}
153-
})
154-
}
155-
156146
pub fn clear_http_request_context() {
157147
APP_HELPERS.with(|helpers| {
158148
helpers.borrow_mut().current_http_context = None;
@@ -171,30 +161,10 @@ pub fn source() -> Address {
171161
})
172162
}
173163

174-
/// Get query parameters from the current HTTP request path (manually parsed)
175-
/// Returns None if not in an HTTP context or no query parameters present
176-
/// NOTE: This manually parses the path string. For pre-parsed params, use get_parsed_query_params()
177-
pub fn get_query_params() -> Option<HashMap<String, String>> {
178-
get_path().map(|path| {
179-
let mut params = HashMap::new();
180-
if let Some(query_start) = path.find('?') {
181-
let query = &path[query_start + 1..];
182-
for pair in query.split('&') {
183-
if let Some(eq_pos) = pair.find('=') {
184-
let key = pair[..eq_pos].to_string();
185-
let value = pair[eq_pos + 1..].to_string();
186-
params.insert(key, value);
187-
}
188-
}
189-
}
190-
params
191-
})
192-
}
193-
194164
/// Get the pre-parsed query parameters from the current HTTP request
195165
/// Returns None if not in an HTTP context
196166
/// This accesses the query_params field that Hyperware already parsed (includes URL decoding)
197-
pub fn get_parsed_query_params() -> Option<HashMap<String, String>> {
167+
pub fn get_query_params() -> Option<HashMap<String, String>> {
198168
APP_HELPERS.with(|helpers| {
199169
helpers
200170
.borrow()

0 commit comments

Comments
 (0)