Skip to main content

waveless_runtime/
lib.rs

1// Waveless
2// Copyright (C) 2026 Oscar Alvarez Gonzalez
3
4pub mod conn_executor;
5pub mod frontend_options;
6pub mod internal_endpoints;
7pub mod runtime_cx;
8pub mod server;
9pub mod services;
10
11pub use conn_executor::*;
12pub use internal_endpoints::*;
13pub use runtime_cx::*;
14pub use services::*;
15
16use waveless_commons::*;
17
18use waveless_commons::endpoint::*;
19use waveless_commons::http_executor::{request_cx::*, *};
20use waveless_commons::object::*;
21use waveless_commons::socket_executor::handshake_cx::*;
22
23use rustyrosetta::*;
24
25use std::cell::LazyCell;
26use std::collections::HashMap;
27use std::convert::Infallible;
28use std::fs::read;
29use std::net::SocketAddr;
30use std::path::PathBuf;
31use std::pin::Pin;
32use std::sync::Arc;
33use std::task::Poll;
34use std::time::Duration;
35
36use bytes::Bytes as ConnBytes;
37use clap::Subcommand;
38use color_eyre::Section;
39use compact_str::*;
40use dashmap::DashMap;
41use derive_more::Constructor;
42use eyre::{Context, Result, eyre};
43use futures::future::BoxFuture;
44use getset::*;
45use http::{HeaderName, HeaderValue, StatusCode};
46use http_body_util::{BodyExt, Empty, Full, combinators::BoxBody};
47use hyper::{Request, Response, body::Incoming};
48use hyper_util::{
49    rt::TokioIo, server::conn::auto::Builder as AutoHttpBuilder, service::TowerToHyperService,
50};
51use matchit::*;
52use rustls::pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject};
53use serde_json::json;
54use tokio::{
55    fs::try_exists,
56    sync::{OnceCell, RwLock},
57};
58use tokio_rustls::*;
59use tower::{Layer, Service, ServiceBuilder, util::BoxCloneService};
60use tower_governor::{governor::*, key_extractor::*};
61use tower_http::{compression::*, cors::*, timeout::*};
62use tower_http_cache::prelude::*;
63use tracing::*;
64
65pub type EndpointRouter = DashMap<HttpMethod, Router<Endpoint>>;
66
67pub type ConnBody = BoxBody<ConnBytes, eyre::Error>;
68
69pub static RUNTIME_CX: OnceCell<RuntimeCx> = OnceCell::const_new();
70
71pub fn json_conn_body(value: &serde_json::Value) -> ConnBody {
72    Full::new(ConnBytes::from(
73        serde_json::to_vec_pretty(value).expect("Payload cannot be serialized into JSON."),
74    ))
75    .map_err(|_| unreachable!())
76    .boxed()
77}
78
79pub fn empty_body() -> ConnBody {
80    Empty::<ConnBytes>::new()
81        .map_err(|_| unreachable!())
82        .boxed()
83}