-
Notifications
You must be signed in to change notification settings - Fork 0
zhr/http request consolidation #18
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few substantive possible changes, and a few smaller ones
hyperprocess_macro/src/lib.rs
Outdated
current_path != "/" && | ||
!current_path.starts_with("/assets") && | ||
!current_path.starts_with("/static") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hyperprocess_macro/src/lib.rs
Outdated
let mut ctx_mut = ctx.borrow_mut(); | ||
ctx_mut.current_path = current_path; | ||
ctx_mut.current_http_method = current_method; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is capturing and restoring context like this required? See 3568d35 which seems to work fine without. If we need it, please add a test that shows how removing this breaks
similar for below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is capturing and restoring context like this required? See 3568d35 which seems to work fine without. If we need it, please add a test that shows how removing this breaks
similar for below
in my testing, I noticed that without context preservation, even if the handler was routed properly, get_path() would return None, which is not ideal
hyperprocess_macro/src/lib.rs
Outdated
// Call the websocket handler if it exists | ||
#ws_method_call | ||
|
||
// Save state if needed | ||
unsafe { | ||
hyperware_app_common::maybe_save_state(&mut *state); | ||
} | ||
hyperware_process_lib::logging::debug!("WebSocket message processed successfully"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend removing this log
hyperprocess_macro/src/lib.rs
Outdated
@@ -1006,28 +1545,50 @@ fn generate_message_handlers( | |||
// Save state if needed | |||
hyperware_app_common::maybe_save_state(&mut *state); | |||
} | |||
hyperware_process_lib::logging::debug!("Local message processed successfully"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommend removing
hyperprocess_macro/src/lib.rs
Outdated
// Process the local request based on our handlers (now including both local and remote handlers) | ||
match serde_json::from_slice::<HPMRequest>(message.body()) { | ||
Ok(request) => { | ||
hyperware_process_lib::logging::debug!("Successfully deserialized local request"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommend removing
hyperprocess_macro/src/lib.rs
Outdated
let mut ctx_mut = ctx.borrow_mut(); | ||
ctx_mut.current_path = Some(current_path.clone()); | ||
ctx_mut.current_http_method = Some(http_method.clone()); | ||
hyperware_process_lib::logging::debug!("Set current_path to: {:?}", ctx_mut.current_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need both this and L1392: remove one
README.md
Outdated
} | ||
``` | ||
|
||
#### **UI Path Conflicts (Critical!):** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussion in this section seems wrong even if we don't remove the ui path hardcoding
README.md
Outdated
|
||
### Smart Routing System | ||
|
||
The framework now uses intelligent priority-based routing that automatically chooses the best handler based on the request: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
framework now uses
->
framework uses
README.md
Outdated
// Set current_http_method to: Some("GET") | ||
``` | ||
|
||
### Enhanced Error Handling (New!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove (New!)
README.md
Outdated
|
||
### Enhanced Error Handling (New!) | ||
|
||
The framework now provides much more detailed error messages for debugging: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More questions: why are we restricting parameter-less #[http]? This PR doesn't have any problems with your test cases (and some code I generated wants to use parameter-less HTTP posts): #20
I am not sure what you mean? The macro supports them well (as per the testing app I showed you) and I updated the WIT parser to handle them as well. |
add response headers
use new process_lib
…esetting remove more path method resetting
add persist on diff
…ss-requests try including parameterless requests
…nsolidation-testing Conflicts: hyperprocess_macro/src/lib.rs
…n-testing http request consolidation testing
Conflicts: hyperprocess_macro/src/lib.rs
TODOs:
|
HTTP request routing:
Problem: All HTTP request were routed by JSON body de-serialization, which prevented simple GET requests from going through (and other methods which might not involve parameters).
Solution: a two-phase http routing system for HTTP requests.
In phase one, we first parse parameter-less HTTP requests (those without an argument in the signature) and order the handlers according to how specific they are (specific here meaning whether they have a defined method, path, both, either, or none). This part was a bit tricky since I kept getting errors where I would hit the wrong handler, but after exhaustive testing it seems to work. One important note here is that parameter-less HTTP handlers don't get added to the HPMRequest enum anymore.
Phase 2 is pretty much how it was done before:
Deserializes request body into HPMRequest enum and matches according to the function arguments.
I also made sure to include some more expressive error handling that touches other parts of the code (not strictly related to HTTP).
This PR is related to another PR on the kit WIT parser that I will make shortly.