diff --git a/src/lib.rs b/src/lib.rs index a6df126..db7b421 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,6 +123,7 @@ pub struct Target { pub handler: String, pub key: Option, pub idempotency_key: Option, + pub headers: Vec
, } #[derive(Debug, Hash, Clone, Copy, Eq, PartialEq)] diff --git a/src/service_protocol/messages.rs b/src/service_protocol/messages.rs index 72bd0ce..3ce2464 100644 --- a/src/service_protocol/messages.rs +++ b/src/service_protocol/messages.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use crate::service_protocol::messages::get_state_keys_entry_message::StateKeys; use crate::service_protocol::{MessageHeader, MessageType}; use crate::vm::errors::{ @@ -455,6 +457,24 @@ impl From for crate::TerminalFailure { } } +impl From
for crate::Header { + fn from(header: Header) -> Self { + Self { + key: Cow::Owned(header.key), + value: Cow::Owned(header.value), + } + } +} + +impl From for Header { + fn from(header: crate::Header) -> Self { + Self { + key: header.key.into(), + value: header.value.into(), + } + } +} + // --- Completion parsing #[derive(Debug)] diff --git a/src/tests/async_result.rs b/src/tests/async_result.rs index e0fafeb..97b634d 100644 --- a/src/tests/async_result.rs +++ b/src/tests/async_result.rs @@ -11,6 +11,7 @@ fn greeter_target() -> Target { handler: "greeter".to_string(), key: None, idempotency_key: None, + headers: Vec::new(), } } diff --git a/src/tests/calls.rs b/src/tests/calls.rs index d43b713..f062f7a 100644 --- a/src/tests/calls.rs +++ b/src/tests/calls.rs @@ -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(), ) @@ -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, diff --git a/src/tests/failures.rs b/src/tests/failures.rs index f0b4608..2ca12d4 100644 --- a/src/tests/failures.rs +++ b/src/tests/failures.rs @@ -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, diff --git a/src/tests/state.rs b/src/tests/state.rs index ee28a4b..bdca3fe 100644 --- a/src/tests/state.rs +++ b/src/tests/state.rs @@ -5,7 +5,6 @@ use assert2::let_assert; use bytes::Bytes; /// Normal state - fn get_state_handler(vm: &mut CoreVM) { vm.sys_input().unwrap(); @@ -349,7 +348,6 @@ mod only_lazy_state { } /// Eager state - mod eager { use super::*; diff --git a/src/vm/mod.rs b/src/vm/mod.rs index a8bd3c7..1ed251a 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -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() }, @@ -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| { diff --git a/src/vm/transitions/journal.rs b/src/vm/transitions/journal.rs index 9af29fe..60864c9 100644 --- a/src/vm/transitions/journal.rs +++ b/src/vm/transitions/journal.rs @@ -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, @@ -121,14 +120,7 @@ impl TransitionAndReturn 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, }, ))