spacegate_model/
route_match.rs

1use serde::{Deserialize, Serialize};
2/// PathMatchType specifies the semantics of how HTTP paths should be compared.
3#[derive(Debug, Serialize, Deserialize, Clone)]
4#[serde(tag = "kind", rename_all = "PascalCase")]
5#[cfg_attr(feature = "typegen", derive(ts_rs::TS), ts(export))]
6pub enum SgHttpPathMatch {
7    /// Matches the URL path exactly and with case sensitivity.
8    Exact {
9        value: String,
10        #[serde(skip_serializing_if = "Option::is_none")]
11        replace: Option<String>,
12    },
13    /// Matches based on a URL path prefix split by /. Matching is case sensitive and done on a path element by element basis.
14    /// A path element refers to the list of labels in the path split by the / separator. When specified, a trailing / is ignored.
15    Prefix {
16        value: String,
17        #[serde(skip_serializing_if = "Option::is_none")]
18        replace: Option<String>,
19    },
20    /// Matches if the URL path matches the given regular expression with case sensitivity.
21    RegExp {
22        value: String,
23        #[serde(skip_serializing_if = "Option::is_none")]
24        replace: Option<String>,
25    },
26}
27
28#[derive(Debug, Serialize, Deserialize, Clone)]
29#[serde(tag = "kind", rename_all = "snake_case")]
30#[cfg_attr(feature = "typegen", derive(ts_rs::TS), ts(export))]
31pub enum SgHttpHeaderMatch {
32    /// Matches the HTTP header exactly and with case sensitivity.
33    Exact {
34        name: String,
35        value: String,
36        #[serde(skip_serializing_if = "Option::is_none")]
37        replace: Option<String>,
38    },
39    /// Matches if the Http header matches the given regular expression with case sensitivity.
40    RegExp {
41        name: String,
42        re: String,
43        #[serde(skip_serializing_if = "Option::is_none")]
44        replace: Option<String>,
45    },
46}
47
48#[derive(Debug, Serialize, Deserialize, Clone)]
49#[serde(tag = "kind", content = "value", rename_all = "snake_case")]
50#[cfg_attr(feature = "typegen", derive(ts_rs::TS), ts(export))]
51pub enum SgHttpQueryMatch {
52    /// Matches the HTTP query parameter exactly and with case sensitivity.
53    Exact { key: String, value: String },
54    /// Matches if the Http query parameter matches the given regular expression with case sensitivity.
55    Regular { key: String, re: String },
56}
57
58#[derive(Default, Debug, Clone, Serialize, Deserialize)]
59#[cfg_attr(feature = "typegen", derive(ts_rs::TS), ts(export))]
60#[serde(transparent)]
61
62pub struct SgHttpMethodMatch(pub String);
63
64/// HTTPRouteMatch defines the predicate used to match requests to a given action.
65/// Multiple match types are ANDed together, i.e. the match will evaluate to true only if all conditions are satisfied.
66#[derive(Default, Debug, Clone, Serialize, Deserialize)]
67#[cfg_attr(feature = "typegen", derive(ts_rs::TS), ts(export))]
68#[serde(default)]
69pub struct SgHttpRouteMatch {
70    #[serde(skip_serializing_if = "Option::is_none")]
71    /// Path specifies a HTTP request path matcher.
72    /// If this field is not specified, a default prefix match on the “/” path is provided.
73    pub path: Option<SgHttpPathMatch>,
74    #[serde(skip_serializing_if = "Option::is_none")]
75    /// Headers specifies HTTP request header matchers.
76    /// Multiple match values are ANDed together, meaning, a request must match all the specified headers to select the route.
77    pub header: Option<Vec<SgHttpHeaderMatch>>,
78    #[serde(skip_serializing_if = "Option::is_none")]
79    /// Query specifies HTTP query parameter matchers.
80    /// Multiple match values are ANDed together, meaning, a request must match all the specified query parameters to select the route.
81    pub query: Option<Vec<SgHttpQueryMatch>>,
82    #[serde(skip_serializing_if = "Option::is_none")]
83    /// Method specifies HTTP method matcher.
84    /// When specified, this route will be matched only if the request has the specified method.
85    pub method: Option<Vec<SgHttpMethodMatch>>,
86}