Skip to content

Commit a4b1187

Browse files
committed
fix(rivetkit): route raw request fetches to actors
1 parent 1ec87a0 commit a4b1187

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

  • rivetkit-rust/packages/rivetkit-core/src/registry

rivetkit-rust/packages/rivetkit-core/src/registry/http.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ impl RegistryDispatcher {
1515
return self.handle_metrics_fetch(&instance, &request);
1616
}
1717

18+
let actor_request = is_actor_request_path(&request.path);
1819
let request = build_http_request(request).await?;
19-
let framework_route = framework_http_route(request.uri().path())?;
20+
let framework_route = if actor_request {
21+
None
22+
} else {
23+
framework_http_route(request.uri().path())?
24+
};
2025
let instance = match self.active_actor(actor_id).await {
2126
Ok(instance) => instance,
2227
Err(error) => {
@@ -567,6 +572,14 @@ pub(super) fn normalize_actor_request_path(path: &str) -> String {
567572
}
568573
}
569574

575+
fn is_actor_request_path(path: &str) -> bool {
576+
let Some(stripped) = path.strip_prefix("/request") else {
577+
return false;
578+
};
579+
580+
stripped.is_empty() || matches!(stripped.as_bytes().first(), Some(b'/') | Some(b'?'))
581+
}
582+
570583
pub(super) fn build_envoy_response(response: Response) -> Result<HttpResponse> {
571584
let (status, headers, body) = response.to_parts();
572585

@@ -905,9 +918,9 @@ mod tests {
905918

906919
use super::{
907920
HttpRequest, HttpResponseEncoding, authorization_bearer_token,
908-
authorization_bearer_token_map, framework_action_error_response,
909-
message_boundary_error_response, request_encoding, request_has_bearer_token,
910-
workflow_dispatch_result,
921+
authorization_bearer_token_map, framework_action_error_response, is_actor_request_path,
922+
message_boundary_error_response, normalize_actor_request_path, request_encoding,
923+
request_has_bearer_token, workflow_dispatch_result,
911924
};
912925
use crate::actor::action::ActionDispatchError;
913926
use crate::error::ActorLifecycle as ActorLifecycleError;
@@ -924,6 +937,21 @@ mod tests {
924937
#[error("message", "outgoing_too_long", "Outgoing message too long")]
925938
struct OutgoingMessageTooLong;
926939

940+
#[test]
941+
fn request_prefix_detection_matches_normalization() {
942+
assert!(is_actor_request_path("/request"));
943+
assert!(is_actor_request_path("/request/"));
944+
assert!(is_actor_request_path("/request/users"));
945+
assert!(is_actor_request_path("/request?foo=bar"));
946+
assert!(!is_actor_request_path("/requestfoo"));
947+
948+
assert_eq!(normalize_actor_request_path("/request"), "/");
949+
assert_eq!(normalize_actor_request_path("/request/"), "/");
950+
assert_eq!(normalize_actor_request_path("/request/users"), "/users");
951+
assert_eq!(normalize_actor_request_path("/request?foo=bar"), "?foo=bar");
952+
assert_eq!(normalize_actor_request_path("/requestfoo"), "/requestfoo");
953+
}
954+
927955
#[test]
928956
fn workflow_dispatch_result_marks_handled_workflow_as_enabled() {
929957
assert_eq!(

0 commit comments

Comments
 (0)