pub struct HttpKernel { /* private fields */ }Expand description
Runs middleware, then the controller, and maps errors to responses.
§Examples
use serenade_http::{HttpKernel, Method, Request, Response};
let kernel = HttpKernel::new(|_request: &mut Request| Ok(Response::text(200, "ok")));
let response = kernel.handle(Request::new(Method::Get, "/healthz"));
assert_eq!(response.status(), 200);
assert_eq!(response.body_str(), Some("ok"));Implementations§
Source§impl HttpKernel
impl HttpKernel
Sourcepub fn new(controller: impl RequestHandler + 'static) -> HttpKernel
pub fn new(controller: impl RequestHandler + 'static) -> HttpKernel
Kernel with controller and DefaultExceptionHandler. No middleware.
Sourcepub fn with_exception_handler(
self,
handler: impl ExceptionHandler + 'static,
) -> HttpKernel
pub fn with_exception_handler( self, handler: impl ExceptionHandler + 'static, ) -> HttpKernel
Replaces the exception mapper.
Sourcepub fn push_middleware(
&mut self,
middleware: impl Middleware + 'static,
) -> &mut HttpKernel
pub fn push_middleware( &mut self, middleware: impl Middleware + 'static, ) -> &mut HttpKernel
Appends middleware. The first pushed layer is outermost (runs first).
Auto Trait Implementations§
impl !RefUnwindSafe for HttpKernel
impl !UnwindSafe for HttpKernel
impl Forget for HttpKernel
impl Freeze for HttpKernel
impl Move for HttpKernel
impl Send for HttpKernel
impl Sync for HttpKernel
impl Unpin for HttpKernel
impl UnsafeUnpin for HttpKernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SerializableKey for T
impl<T> SerializableKey for T
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.