pub struct Rpress { /* private fields */ }Expand description
Async HTTP/1.1 and HTTP/2 server with routing, middleware, compression, and more.
Create an instance with Rpress::new, configure it with builder methods, add route
groups via add_route_group, then call
listen or listen_tls to start serving.
Implementations§
Source§impl Rpress
impl Rpress
Sourcepub fn new(cors: Option<RpressCors>) -> Self
pub fn new(cors: Option<RpressCors>) -> Self
Creates a new Rpress instance with optional CORS configuration.
Sourcepub fn set_buffer_capacity(&mut self, capacity: usize)
pub fn set_buffer_capacity(&mut self, capacity: usize)
Sets the maximum buffer capacity per connection in bytes.
Sourcepub fn set_read_timeout(&mut self, duration: Duration)
pub fn set_read_timeout(&mut self, duration: Duration)
Sets the read timeout for incoming data on a connection.
Sourcepub fn set_idle_timeout(&mut self, duration: Duration)
pub fn set_idle_timeout(&mut self, duration: Duration)
Sets the idle timeout before a keep-alive connection is closed.
Sourcepub fn set_max_connections(&mut self, max: usize)
pub fn set_max_connections(&mut self, max: usize)
Sets the maximum number of concurrent connections.
Sourcepub fn use_middleware<F, Fut>(&mut self, middleware: F)where
F: Fn(RequestPayload, Next) -> Fut + Send + Sync + 'static,
Fut: Future<Output = RpressResult> + Send + 'static,
pub fn use_middleware<F, Fut>(&mut self, middleware: F)where
F: Fn(RequestPayload, Next) -> Fut + Send + Sync + 'static,
Fut: Future<Output = RpressResult> + Send + 'static,
Registers a global middleware that runs on every request.
Sourcepub fn add_route_group(&mut self, group: RpressRoutes)
pub fn add_route_group(&mut self, group: RpressRoutes)
Adds a route group with its own routes and optional group-level middleware.
Sourcepub fn serve_static(&mut self, url_prefix: &str, dir: &str)
pub fn serve_static(&mut self, url_prefix: &str, dir: &str)
Registers a directory for serving static files at the given URL prefix.
Sourcepub fn set_rate_limit(&mut self, max_requests: u32, window_secs: u64)
pub fn set_rate_limit(&mut self, max_requests: u32, window_secs: u64)
Enables IP-based rate limiting with the given max requests per time window.
Uses an in-memory rate limiter by default. For distributed environments,
call set_rate_limiter first to inject a custom backend.
Sourcepub fn set_rate_limiter(&mut self, limiter: impl RateLimiter)
pub fn set_rate_limiter(&mut self, limiter: impl RateLimiter)
Sets a custom rate limiter backend (e.g. Redis-backed for distributed deployments).
Must be called before set_rate_limit to take effect,
or after it to replace the default in-memory limiter.
Sourcepub fn enable_compression(&mut self, enabled: bool)
pub fn enable_compression(&mut self, enabled: bool)
Enables or disables automatic gzip/brotli response compression.
Sourcepub fn set_max_body_size(&mut self, bytes: usize)
pub fn set_max_body_size(&mut self, bytes: usize)
Sets the global maximum request body size in bytes (default: 10MB).
Sourcepub fn set_stream_threshold(&mut self, bytes: usize)
pub fn set_stream_threshold(&mut self, bytes: usize)
Sets the body size threshold (in bytes) above which request bodies are streamed.
Sourcepub async fn listen<T: Into<String>>(self, addr: T) -> Result<()>
pub async fn listen<T: Into<String>>(self, addr: T) -> Result<()>
Binds to the given address and starts accepting connections.
Sourcepub async fn server_with_listener(self, listener: TcpListener) -> Result<()>
pub async fn server_with_listener(self, listener: TcpListener) -> Result<()>
Starts the server using an existing TcpListener.
Sourcepub async fn listen_tls<T: Into<String>>(
self,
addr: T,
tls_config: RpressTlsConfig,
) -> Result<()>
pub async fn listen_tls<T: Into<String>>( self, addr: T, tls_config: RpressTlsConfig, ) -> Result<()>
Binds to the given address and starts accepting TLS connections.
Sourcepub async fn server_with_listener_tls(
self,
listener: TcpListener,
tls_config: RpressTlsConfig,
) -> Result<()>
pub async fn server_with_listener_tls( self, listener: TcpListener, tls_config: RpressTlsConfig, ) -> Result<()>
Starts the TLS server using an existing TcpListener.