recast_lang/ast/protocol.rs
1//! Protocol Definition related AST
2use crate::ast::action::RapidRecastAction;
3use serde::{Deserialize, Serialize};
4use std::borrow::Cow;
5
6/// A Protocol Definition
7/// The type of protocol used for the protocol definition
8#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
9pub enum RapidProtocolDefinition<'a> {
10 /// Indicates that we are modifying an HTTP protocol
11 HttpProtocolDefinition(HttpStatement<'a>),
12}
13
14/// Allows for specifying parts of an HTTP statement
15#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
16pub struct HttpStatement<'a> {
17 /// Protocol sequence, where the order is determined from CLI order
18 /// ex. `rapidrecast --http host1:123,host1:234,host2:345`
19 /// That declares 3 protocols, so `sequence=2` means binding `host2:345`
20 pub sequence: u8,
21 /// The paths to match on the HTTP protocol
22 pub paths: Vec<Cow<'a, str>>,
23 /// The methods of access for this rule. GET, POST, DELETE, UPDATE
24 pub methods: Vec<RapidRecastHttpMethod>,
25 /// Actions that take effect once the protocol is triggered
26 pub actions: Vec<RapidRecastAction<'a>>,
27}
28
29/// Http Methods supported by RapidRecast
30#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
31pub enum RapidRecastHttpMethod {
32 /// Get Method
33 GET,
34 /// Post Method
35 POST,
36 /// Delete Method
37 DELETE,
38 /// Update Method
39 UPDATE,
40 /// Patch Method
41 PATCH,
42 /// Put Method
43 PUT,
44 /// Options Method
45 OPTIONS,
46 /// Head Method
47 HEAD,
48 /// Connect Method
49 CONNECT,
50 /// Trace Method
51 TRACE,
52}
53
54/// The protocols available in RapidRecast
55#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
56pub enum RapidRecastProtocolType {
57 /// HTTP 1,2, and 3 protocols
58 HTTP,
59 /// WebSockets on HTTP 1, 2, and 3 - it is a different model of communication from HTTP 2/3 streams
60 WebSocket,
61 /// Kafka protocol
62 Kafka,
63 /// RabbitMQ protocol
64 RabbitMQ,
65 /// gRPC protocol
66 Grpc,
67}