Skip to content

add http_method #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 6 additions & 2 deletions hyperprocess_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,9 @@ fn generate_message_handlers(
match http_server_request {
hyperware_process_lib::http::server::HttpServerRequest::Http(http_request) => {
hyperware_app_common::APP_HELPERS.with(|ctx| {
ctx.borrow_mut().current_path = Some(http_request.path().clone().expect("Failed to get path from HTTP request"));
let mut ctx_mut = ctx.borrow_mut();
ctx_mut.current_path = Some(http_request.path().clone().expect("Failed to get path from HTTP request"));
ctx_mut.http_method = http_request.method().clone();
});

// Get the blob containing the actual request
Expand Down Expand Up @@ -962,7 +964,9 @@ fn generate_message_handlers(
}
}
hyperware_app_common::APP_HELPERS.with(|ctx| {
ctx.borrow_mut().current_path = None;
let mut ctx_mut = ctx.borrow_mut();
ctx_mut.current_path = None;
ctx_mut.http_method = None;
});
},
hyperware_process_lib::http::server::HttpServerRequest::WebSocketPush { channel_id, message_type } => {
Expand Down
12 changes: 12 additions & 0 deletions hyperware_app_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ thread_local! {
current_path: None,
current_server: None,
current_message: None,
http_method: None,
});
}

Expand All @@ -47,6 +48,7 @@ pub struct AppHelpers {
pub current_path: Option<String>,
pub current_server: Option<*mut HttpServer>,
pub current_message: Option<Message>,
pub http_method: Option<http::Method>,
}

// Access function for the current path
Expand All @@ -71,6 +73,16 @@ pub fn source() -> hyperware_process_lib::Address {
})
}

// Access function for the HTTP method of the current request
pub fn http_method() -> http::Method {
APP_CONTEXT.with(|ctx| {
ctx.borrow()
.http_method
.clone()
.expect("No HTTP method in current context")
})
}

pub struct Executor {
tasks: Vec<Pin<Box<dyn Future<Output = ()>>>>,
}
Expand Down