Skip to content

Commit

Permalink
Support headers in service to service call/send
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Dec 6, 2024
1 parent b6e7963 commit b6285c6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ pub struct Header {
pub value: Cow<'static, str>,
}

impl From<service_protocol::messages::Header> for Header {
fn from(header: service_protocol::messages::Header) -> Self {
Self {
key: Cow::Owned(header.key),
value: Cow::Owned(header.value),
}
}
}

impl From<Header> for service_protocol::messages::Header {
fn from(header: Header) -> Self {
Self {
key: header.key.into(),
value: header.value.into(),
}
}
}

#[derive(Debug)]
pub struct ResponseHead {
pub status_code: u16,
Expand Down Expand Up @@ -123,6 +141,7 @@ pub struct Target {
pub handler: String,
pub key: Option<String>,
pub idempotency_key: Option<String>,
pub headers: Vec<Header>,
}

#[derive(Debug, Hash, Clone, Copy, Eq, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions src/tests/async_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn greeter_target() -> Target {
handler: "greeter".to_string(),
key: None,
idempotency_key: None,
headers: Vec::new(),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/tests/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn call_then_get_invocation_id_then_cancel_invocation() {
handler: "MyHandler".to_string(),
key: None,
idempotency_key: None,
headers: Vec::new(),
},
Bytes::new(),
)
Expand Down Expand Up @@ -113,6 +114,7 @@ fn send_then_get_invocation_id_then_cancel_invocation() {
handler: "MyHandler".to_string(),
key: None,
idempotency_key: None,
headers: Vec::new(),
},
Bytes::new(),
None,
Expand Down
1 change: 1 addition & 0 deletions src/tests/failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn one_way_call_entry_mismatch() {
handler: "greet".to_owned(),
key: Some("my-key".to_owned()),
idempotency_key: None,
headers: Vec::new(),
},
Bytes::from_static(b"456"),
None,
Expand Down
10 changes: 10 additions & 0 deletions src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ impl super::VM for CoreVM {
handler_name: target.handler,
key: target.key.unwrap_or_default(),
idempotency_key: target.idempotency_key,
headers: target
.headers
.into_iter()
.map(crate::service_protocol::messages::Header::from)
.collect(),
parameter: input,
..Default::default()
},
Expand Down Expand Up @@ -491,6 +496,11 @@ impl super::VM for CoreVM {
handler_name: target.handler,
key: target.key.unwrap_or_default(),
idempotency_key: target.idempotency_key,
headers: target
.headers
.into_iter()
.map(crate::service_protocol::messages::Header::from)
.collect(),
parameter: input,
invoke_time: delay
.map(|d| {
Expand Down
10 changes: 1 addition & 9 deletions src/vm/transitions/journal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::retries::NextRetry;
use crate::service_protocol::messages;
use crate::service_protocol::messages::{
run_entry_message, CompletableEntryMessage, EntryMessage, EntryMessageHeaderEq,
InputEntryMessage, RestateMessage, RunEntryMessage, WriteableRestateMessage,
Expand Down Expand Up @@ -121,14 +120,7 @@ impl TransitionAndReturn<Context, SysInput> for State {
invocation_id: start_info.debug_id.clone(),
random_seed: compute_random_seed(&start_info.id),
key: start_info.key.clone(),
headers: msg
.headers
.into_iter()
.map(|messages::Header { key, value }| Header {
key: key.into(),
value: value.into(),
})
.collect(),
headers: msg.headers.into_iter().map(Header::from).collect(),
input: msg.value,
},
))
Expand Down

0 comments on commit b6285c6

Please sign in to comment.