sozu_lib/protocol/mod.rs
1pub mod h2;
2pub mod kawa_h1;
3pub mod pipe;
4pub mod proxy_protocol;
5pub mod rustls;
6
7use std::{cell::RefCell, rc::Rc};
8
9use mio::Token;
10use sozu_command::ready::Ready;
11
12use crate::{
13 L7Proxy, ProxySession, SessionIsToBeClosed, SessionMetrics, SessionResult, StateResult,
14};
15
16pub use crate::protocol::{
17 http::Http, kawa_h1 as http, pipe::Pipe, proxy_protocol::send::SendProxyProtocol,
18 rustls::TlsHandshake,
19};
20
21/// All States should satisfy this trait in order to receive and handle Session events
22pub trait SessionState {
23 /// if a session received an event or can still execute, the event loop will
24 /// call this method. Its result indicates if it can still execute or if the
25 /// session can be closed
26 fn ready(
27 &mut self,
28 session: Rc<RefCell<dyn ProxySession>>,
29 proxy: Rc<RefCell<dyn L7Proxy>>,
30 metrics: &mut SessionMetrics,
31 ) -> SessionResult;
32 /// if the event loop got an event for a token associated with the session,
33 /// it will call this method
34 fn update_readiness(&mut self, token: Token, events: Ready);
35 /// close the state
36 fn close(&mut self, _proxy: Rc<RefCell<dyn L7Proxy>>, _metrics: &mut SessionMetrics) {}
37 /// if a timeout associated with the session triggers, the event loop will
38 /// call this method with the timeout's token
39 fn timeout(&mut self, token: Token, metrics: &mut SessionMetrics) -> StateResult;
40 /// cancel frontend timeout (and backend timeout if present)
41 fn cancel_timeouts(&mut self);
42 /// display the session's internal state (for debugging purpose),
43 /// ```plain
44 /// <context> Session(<State name>):
45 /// Frontend:
46 /// - Token(...) Readiness(...)
47 /// Backends:
48 /// - Token(...) Readiness(...)
49 /// - Token(...) Readiness(...)
50 /// ```
51 fn print_state(&self, context: &str);
52 /// tell the session it has to shut down if possible
53 ///
54 /// if the session handles HTTP requests, it will not close until the response
55 /// is completely sent back to the client
56 fn shutting_down(&mut self) -> SessionIsToBeClosed {
57 true
58 }
59}