-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathcustom_serve.rs
More file actions
56 lines (51 loc) · 1.47 KB
/
custom_serve.rs
File metadata and controls
56 lines (51 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use anyhow::{Result, bail};
use async_trait::async_trait;
use bytes::Bytes;
use http_body_util::Full;
use hyper::{Request, Response};
use rivet_runner_protocol as protocol;
use rivet_util::Id;
use tokio_tungstenite::tungstenite::protocol::frame::CloseFrame;
use crate::WebSocketHandle;
use crate::proxy_service::ResponseBody;
pub enum HibernationResult {
Continue,
Close,
}
/// Trait for custom request serving logic that can handle both HTTP and WebSocket requests
#[async_trait]
pub trait CustomServeTrait: Send + Sync {
/// Handle a regular HTTP request
async fn handle_request(
&self,
req: Request<Full<Bytes>>,
ray_id: Id,
req_id: Id,
request_id: protocol::RequestId,
) -> Result<Response<ResponseBody>>;
/// Handle a WebSocket connection after upgrade. Supports connection retries.
async fn handle_websocket(
&self,
_websocket: WebSocketHandle,
_headers: &hyper::HeaderMap,
_path: &str,
_ray_id: Id,
_req_id: Id,
// Identifies the websocket across retries.
_request_id: protocol::RequestId,
// True if this websocket is reconnecting after hibernation.
_after_hibernation: bool,
) -> Result<Option<CloseFrame>> {
bail!("service does not support websockets");
}
/// Returns true if the websocket should close.
async fn handle_websocket_hibernation(
&self,
_websocket: WebSocketHandle,
_ray_id: Id,
_req_id: Id,
_request_id: protocol::RequestId,
) -> Result<HibernationResult> {
bail!("service does not support websocket hibernation");
}
}