Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

A native HTTP/1 server whose request execution remains thread-local.

Keeping one compiled app per worker means operation futures, plugin hooks, and request-scoped dependencies do not need Send or Sync.

Implementations§

Source§

impl Server

Source

pub fn new(app: ExecutableApp) -> Self

Source

pub fn with_max_body_bytes(self, max_body_bytes: usize) -> Self

Source

pub fn with_middleware(self, middleware: impl HttpMiddleware + 'static) -> Self

Registers runtime-neutral HTTP middleware in registration order.

Middleware runs for every request this server dispatches, so header policy, compression, rate limiting, and security layers apply on the socket path and not only in the in-memory test client.

Source

pub fn with_shared_middleware(self, middleware: Rc<dyn HttpMiddleware>) -> Self

Registers middleware whose state is shared with the caller.

Source

pub const fn with_max_connections( self, connections: Option<NonZeroUsize>, ) -> Self

Bounds concurrently served connections. None accepts without a cap.

A connection accepted while the cap is reached is closed immediately instead of being dispatched.

Source

pub const fn with_tcp_nodelay(self, nodelay: bool) -> Self

Enables or disables TCP_NODELAY on accepted sockets. Enabled by default so a small response is not delayed by Nagle’s algorithm.

Source

pub fn with_limits(self, limits: ServerLimits) -> Self

Source

pub fn with_openapi(self, config: OpenApiConfig) -> Self

Mounts precompiled /openapi.json and API reference UI assets.

Source

pub const fn with_request_timeout(self, timeout: Duration) -> Self

Sets a wall-clock limit for provider, hook, and handler execution.

Dependency finalizers and response hooks are shielded so cleanup still completes after the timeout fires.

Source

pub fn serve(self, address: impl ToSocketAddrs) -> Result<()>

Binds and serves HTTP/1 connections until the process is stopped.

§Errors

Returns a socket error if address resolution, binding, or accepting a connection fails.

Source

pub fn serve_gracefully( self, address: impl ToSocketAddrs, shutdown: ShutdownSignal, drain_timeout: Duration, ) -> Result<()>

Stops accepting when shutdown resolves, closes keep-alive connections after their current response, and drains active work.

§Errors

Returns an I/O error if binding or accepting a connection fails.

Source

pub async fn serve_io<IO>(&self, io: &mut IO) -> Result<()>
where IO: AsyncRead + AsyncWrite + Unpin,

Serves HTTP/1 requests over a borrowed futures-I/O transport.

This is useful for in-memory protocol tests. A borrowed transport cannot transfer ownership, so protocol upgrades are refused here; owned transports reach Self::serve and keep the upgrade capability.

§Errors

Returns an I/O error if the transport cannot be read or written.

Source

pub async fn serve_owned_io<IO>(&self, io: IO) -> Result<()>
where IO: AsyncRead + AsyncWrite + Unpin + 'static,

Serves HTTP/1 requests over an owned futures-I/O transport.

Ownership stays with the connection loop, so a protocol upgrade moves the transport into its session handler instead of being refused. TLS connections and in-memory compatibility transports take this path.

§Errors

Returns an I/O error if the transport cannot be read or written, or the failure reported by an upgraded protocol session.

Trait Implementations§

Source§

impl Debug for Server

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Server

§

impl !Send for Server

§

impl !Sync for Server

§

impl !UnwindSafe for Server

§

impl Freeze for Server

§

impl Unpin for Server

§

impl UnsafeUnpin for Server

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> BackgroundExt for T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ResponseExt for T

Source§

fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> WithHeaders<Self>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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