Skip to main content

Rpress

Struct Rpress 

Source
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

Source

pub fn new(cors: Option<RpressCors>) -> Self

Creates a new Rpress instance with optional CORS configuration.

Source

pub fn set_buffer_capacity(&mut self, capacity: usize)

Sets the maximum buffer capacity per connection in bytes.

Source

pub fn set_read_timeout(&mut self, duration: Duration)

Sets the read timeout for incoming data on a connection.

Source

pub fn set_idle_timeout(&mut self, duration: Duration)

Sets the idle timeout before a keep-alive connection is closed.

Source

pub fn set_max_connections(&mut self, max: usize)

Sets the maximum number of concurrent connections.

Source

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.

Source

pub fn add_route_group(&mut self, group: RpressRoutes)

Adds a route group with its own routes and optional group-level middleware.

Source

pub fn serve_static(&mut self, url_prefix: &str, dir: &str)

Registers a directory for serving static files at the given URL prefix.

Source

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.

Source

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.

Source

pub fn enable_compression(&mut self, enabled: bool)

Enables or disables automatic gzip/brotli response compression.

Source

pub fn set_max_body_size(&mut self, bytes: usize)

Sets the global maximum request body size in bytes (default: 10MB).

Source

pub fn set_stream_threshold(&mut self, bytes: usize)

Sets the body size threshold (in bytes) above which request bodies are streamed.

Source

pub async fn listen<T: Into<String>>(self, addr: T) -> Result<()>

Binds to the given address and starts accepting connections.

Source

pub async fn server_with_listener(self, listener: TcpListener) -> Result<()>

Starts the server using an existing TcpListener.

Source

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.

Source

pub async fn server_with_listener_tls( self, listener: TcpListener, tls_config: RpressTlsConfig, ) -> Result<()>

Starts the TLS server using an existing TcpListener.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more