Skip to main content

relay_core_lib/rule/engine/actions/
mod.rs

1pub mod common;
2pub mod http;
3pub mod transform;
4pub mod utils;
5pub mod ws;
6
7use crate::rule::engine::executor::ExecutionContext;
8use crate::rule::model::{Action, TerminalReason};
9use relay_core_api::flow::Flow;
10
11#[derive(Debug, Clone)]
12pub enum ActionOutcome {
13    Continue,
14    Terminated(TerminalReason),
15    Failed(String),
16}
17
18pub async fn execute_action(
19    action: &Action,
20    flow: &mut Flow,
21    ctx: &mut ExecutionContext,
22) -> ActionOutcome {
23    match action {
24        Action::Drop
25        | Action::Abort
26        | Action::Inspect
27        | Action::Delay { .. }
28        | Action::SetVariable { .. }
29        | Action::Tag { .. }
30        | Action::RedirectIp { .. }
31        | Action::SetTtl { .. }
32        | Action::ForwardPort { .. }
33        | Action::MapRemote { .. }
34        | Action::RateLimit { .. }
35        | Action::Throttle { .. } => common::execute(action, flow, ctx).await,
36
37        Action::SetRequestMethod { .. }
38        | Action::SetRequestUrl { .. }
39        | Action::SetRequestBody { .. }
40        | Action::SetResponseStatus { .. }
41        | Action::SetResponseBody { .. }
42        | Action::Redirect { .. }
43        | Action::AddRequestHeader { .. }
44        | Action::UpdateRequestHeader { .. }
45        | Action::DeleteRequestHeader { .. }
46        | Action::AddResponseHeader { .. }
47        | Action::UpdateResponseHeader { .. }
48        | Action::DeleteResponseHeader { .. }
49        | Action::MockResponse { .. }
50        | Action::MapLocal { .. }
51        | Action::TransformRequestBody { .. }
52        | Action::TransformResponseBody { .. } => http::execute(action, flow, ctx).await,
53
54        Action::MockWebSocketMessage { .. } | Action::DropWebSocketMessage => {
55            ws::execute(action, flow).await
56        }
57    }
58}