diff --git a/src/hyperapp.rs b/src/hyperapp.rs index f0b8e88..7bfe9ce 100644 --- a/src/hyperapp.rs +++ b/src/hyperapp.rs @@ -37,6 +37,7 @@ thread_local! { pub struct HttpRequestContext { pub request: IncomingHttpRequest, pub response_headers: HashMap, + pub response_status: http::StatusCode, } pub struct AppContext { @@ -95,6 +96,15 @@ pub fn add_response_header(key: String, value: String) { }) } +// Set the HTTP response status code +pub fn set_response_status(status: http::StatusCode) { + APP_HELPERS.with(|helpers| { + if let Some(ctx) = &mut helpers.borrow_mut().current_http_context { + ctx.response_status = status; + } + }) +} + pub fn clear_http_request_context() { APP_HELPERS.with(|helpers| { helpers.borrow_mut().current_http_context = None;