Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/hyperapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ thread_local! {
pub struct HttpRequestContext {
pub request: IncomingHttpRequest,
pub response_headers: HashMap<String, String>,
pub response_status: http::StatusCode,
}

pub struct AppContext {
Expand Down Expand Up @@ -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;
Expand Down