Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,16 +1080,6 @@ impl HttpServer {

/// Send an HTTP response to an incoming HTTP request ([`HttpServerRequest::Http`]).
pub fn send_response(status: StatusCode, headers: Option<HashMap<String, String>>, body: Vec<u8>) {
// Check if there's a manual body override in the HTTP context
let final_body = crate::hyperapp::APP_HELPERS.with(|helpers| {
helpers
.borrow()
.current_http_context
.as_ref()
.and_then(|ctx| ctx.response_body.clone())
.unwrap_or(body) // Use override if present, otherwise use the parameter
});

KiResponse::new()
.body(
serde_json::to_vec(&HttpResponse {
Expand All @@ -1098,7 +1088,7 @@ pub fn send_response(status: StatusCode, headers: Option<HashMap<String, String>
})
.unwrap(),
)
.blob_bytes(final_body)
.blob_bytes(body)
.send()
.unwrap()
}
Expand Down
32 changes: 1 addition & 31 deletions src/hyperapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub struct HttpRequestContext {
pub request: IncomingHttpRequest,
pub response_headers: HashMap<String, String>,
pub response_status: http::StatusCode,
pub response_body: Option<Vec<u8>>,
}

pub struct AppContext {
Expand Down Expand Up @@ -144,15 +143,6 @@ pub fn set_response_status(status: http::StatusCode) {
})
}

// Set the HTTP response body directly (bypasses Result serialization)
pub fn set_response_body(body: Vec<u8>) {
APP_HELPERS.with(|helpers| {
if let Some(ctx) = &mut helpers.borrow_mut().current_http_context {
ctx.response_body = Some(body);
}
})
}

pub fn clear_http_request_context() {
APP_HELPERS.with(|helpers| {
helpers.borrow_mut().current_http_context = None;
Expand All @@ -171,30 +161,10 @@ pub fn source() -> Address {
})
}

/// Get query parameters from the current HTTP request path (manually parsed)
/// Returns None if not in an HTTP context or no query parameters present
/// NOTE: This manually parses the path string. For pre-parsed params, use get_parsed_query_params()
pub fn get_query_params() -> Option<HashMap<String, String>> {
get_path().map(|path| {
let mut params = HashMap::new();
if let Some(query_start) = path.find('?') {
let query = &path[query_start + 1..];
for pair in query.split('&') {
if let Some(eq_pos) = pair.find('=') {
let key = pair[..eq_pos].to_string();
let value = pair[eq_pos + 1..].to_string();
params.insert(key, value);
}
}
}
params
})
}

/// Get the pre-parsed query parameters from the current HTTP request
/// Returns None if not in an HTTP context
/// This accesses the query_params field that Hyperware already parsed (includes URL decoding)
pub fn get_parsed_query_params() -> Option<HashMap<String, String>> {
pub fn get_query_params() -> Option<HashMap<String, String>> {
APP_HELPERS.with(|helpers| {
helpers
.borrow()
Expand Down