Skip to content

Commit b7f9f03

Browse files
authored
Merge pull request #167 from hyperware-ai/j/error-codes
Feature: add HTTP error codes from hyperapp
2 parents d67b65e + e8b0651 commit b7f9f03

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/hyperapp.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ thread_local! {
3737
pub struct HttpRequestContext {
3838
pub request: IncomingHttpRequest,
3939
pub response_headers: HashMap<String, String>,
40+
pub response_status: http::StatusCode,
4041
}
4142

4243
pub struct AppContext {
@@ -95,6 +96,15 @@ pub fn add_response_header(key: String, value: String) {
9596
})
9697
}
9798

99+
// Set the HTTP response status code
100+
pub fn set_response_status(status: http::StatusCode) {
101+
APP_HELPERS.with(|helpers| {
102+
if let Some(ctx) = &mut helpers.borrow_mut().current_http_context {
103+
ctx.response_status = status;
104+
}
105+
})
106+
}
107+
98108
pub fn clear_http_request_context() {
99109
APP_HELPERS.with(|helpers| {
100110
helpers.borrow_mut().current_http_context = None;

0 commit comments

Comments
 (0)