Skip to main content

HttpContext

Struct HttpContext 

pub struct HttpContext { /* private fields */ }
Expand description

This struct represents the shared configuration and context for a http server.

This currently contains tunable parameters in a HttpConfig, the Swansong graceful shutdown control interface, and a shared TypeSet that contains application-specific information about the running server

Implementations§

§

impl HttpContext

pub fn config(&self) -> &HttpConfig

Borrows HttpConfig performance and security parameters

pub fn config_mut(&mut self) -> &mut HttpConfig

Mutably borrow HttpConfig performance and security parameters

pub fn set_config(&mut self, config: HttpConfig) -> &mut HttpContext

Sets HttpConfig performance and security parameters, returning &mut Self for chaining

pub fn with_config(self, config: HttpConfig) -> HttpContext

Owned chainable setter for HttpConfig performance and security parameters, returning Self

pub fn swansong(&self) -> &Swansong

Borrows Swansong graceful shutdown interface

pub fn swansong_mut(&mut self) -> &mut Swansong

Mutably borrow Swansong graceful shutdown interface

pub fn set_swansong(&mut self, swansong: Swansong) -> &mut HttpContext

Sets Swansong graceful shutdown interface, returning &mut Self for chaining

pub fn with_swansong(self, swansong: Swansong) -> HttpContext

Owned chainable setter for Swansong graceful shutdown interface, returning Self

pub fn shared_state(&self) -> &TypeSet

Borrows TypeSet shared state

pub fn shared_state_mut(&mut self) -> &mut TypeSet

Mutably borrow TypeSet shared state

pub fn set_shared_state(&mut self, shared_state: TypeSet) -> &mut HttpContext

Sets TypeSet shared state, returning &mut Self for chaining

pub fn with_shared_state(self, shared_state: TypeSet) -> HttpContext

Owned chainable setter for TypeSet shared state, returning Self

§

impl HttpContext

pub fn new() -> HttpContext

Construct a new HttpContext

pub async fn run<Transport, Handler, Fut>( self: Arc<HttpContext>, transport: Transport, handler: Handler, ) -> Result<Option<Upgrade<Transport>>, Error>
where Transport: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static, Handler: FnMut(Conn<Transport>) -> Fut, Fut: Future<Output = Conn<Transport>>,

Perform HTTP on the provided transport, applying the provided async Conn -> Conn handler function for every distinct http request-response.

For any given invocation of HttpContext::run, the handler function may run any number of times, depending on whether the connection is reused by the client.

This can only be called on an Arc<HttpContext> because an arc clone is moved into the Conn.

§Errors

This function will return an Error if any of the http requests is irrecoverably malformed or otherwise noncompliant.

pub fn shut_down(&self) -> ShutdownCompletion

Attempt graceful shutdown of this server.

The returned ShutdownCompletion type can either be awaited in an async context or blocked on with ShutdownCompletion::block in a blocking context

Trait Implementations§

§

impl AsMut<TypeSet> for HttpContext

§

fn as_mut(&mut self) -> &mut TypeSet

Converts this type into a mutable reference of the (usually inferred) input type.
§

impl AsRef<HttpConfig> for HttpContext

§

fn as_ref(&self) -> &HttpConfig

Converts this type into a shared reference of the (usually inferred) input type.
§

impl AsRef<Swansong> for HttpContext

§

fn as_ref(&self) -> &Swansong

Converts this type into a shared reference of the (usually inferred) input type.
§

impl AsRef<TypeSet> for HttpContext

§

fn as_ref(&self) -> &TypeSet

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Debug for HttpContext

§

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

Formats the value using the given formatter. Read more
§

impl Default for HttpContext

§

fn default() -> HttpContext

Returns the “default value” for a type. Read more
Source§

impl From<HttpContext> for Info

Source§

fn from(value: HttpContext) -> Self

Converts to this type from the input type.
Source§

impl From<Info> for HttpContext

Source§

fn from(value: Info) -> Self

Converts to this type from the input type.

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, 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.