Skip to main content

waveless_commons/http_executor/
pipeline_cx.rs

1// Waveless
2// Copyright (C) 2026 Oscar Alvarez Gonzalez
3
4use crate::*;
5
6use super::*;
7
8/// Contains both the current context of the pipeline, passing the request and the candidate response.
9#[derive(Getters, MutGetters)]
10#[getset(get = "pub", get_mut = "pub")]
11pub struct PipelineCx {
12    /// Incoming request from the client (which might have been modified
13    /// by a pipeline's step).
14    pub request: RequestCx,
15
16    /// Outbound response (which might be modified by children execution steps).
17    /// NOTE: if there is no response set, an empty 200 response will be sent back.
18    pub response: Option<ResponseCx>,
19}
20
21impl From<(RequestCx, ResponseCx)> for PipelineCx {
22    fn from(value: (RequestCx, ResponseCx)) -> Self {
23        let (request, response) = value;
24        PipelineCx {
25            request,
26            response: Some(response),
27        }
28    }
29}
30
31impl From<(RequestCx, Option<ResponseCx>)> for PipelineCx {
32    fn from(value: (RequestCx, Option<ResponseCx>)) -> Self {
33        let (request, response) = value;
34        PipelineCx { request, response }
35    }
36}
37
38impl From<PipelineCx> for (RequestCx, Option<ResponseCx>) {
39    fn from(value: PipelineCx) -> Self {
40        let PipelineCx {
41            request, response, ..
42        } = value;
43
44        (request, response)
45    }
46}
47
48impl PipelineCx {
49    /// Creates a new pipeline context with the given request.
50    pub fn new(request: RequestCx) -> Self {
51        Self {
52            request,
53            response: None,
54        }
55    }
56}
57
58/// Determines whether to continue execution with the optionally given child
59/// or abort the execution and return the current response.
60#[derive(Default, Debug)]
61pub enum PipelineAction {
62    /// Continue to the next established executor.
63    /// NOTE: if there is none it will finish.
64    /// NOTE: if there are multiple children the first one will be executed.
65    Continue(Option<ExecutionAtomId>),
66
67    /// Finish execution flow and immediately return the current response.
68    #[default]
69    Finish,
70}