Skip to main content

gproxy_transform/transform/
context.rs

1use crate::protocol::OperationKey;
2
3/// Per-call transform settings.
4///
5/// `path`/`query` carry the INBOUND request target (provider-relative, as the
6/// client sent it) for transforms that need more than the body — e.g. the
7/// list-models query conversion. They are filled on the request direction via
8/// [`with_request`](Self::with_request); response-direction contexts leave
9/// them empty.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct TransformContext {
12    pub source: OperationKey,
13    pub target: OperationKey,
14    pub path: String,
15    pub query: Option<String>,
16}
17
18impl TransformContext {
19    pub fn new(source: OperationKey, target: OperationKey) -> Self {
20        Self {
21            source,
22            target,
23            path: String::new(),
24            query: None,
25        }
26    }
27
28    /// Attach the inbound request target (request-direction contexts).
29    pub fn with_request(mut self, path: &str, query: Option<&str>) -> Self {
30        self.path = path.to_owned();
31        self.query = query.map(str::to_owned);
32        self
33    }
34}