Struct actix_web_lab::guard::Acceptable
source · pub struct Acceptable { /* private fields */ }
👎Deprecated since 0.19.0: Type has graduated to Actix Web.
Expand description
A guard that verifies that an Accept
header is present and it contains a compatible MIME type.
An exception is that matching */*
must be explicitly enabled because most browsers send this
as part of their Accept
header for almost every request.
§Examples
use actix_web::{web, HttpResponse};
use actix_web_lab::guard::Acceptable;
web::resource("/images")
.guard(Acceptable::new(mime::IMAGE_STAR))
.default_service(web::to(|| async {
HttpResponse::Ok().body("only called when images responses are acceptable")
}));
Implementations§
source§impl Acceptable
impl Acceptable
sourcepub fn new(mime: Mime) -> Self
pub fn new(mime: Mime) -> Self
Constructs new Acceptable
guard with the given mime
type/pattern.
sourcepub fn match_star_star(self) -> Self
pub fn match_star_star(self) -> Self
Allows */*
in the Accept
header to pass the guard check.
Trait Implementations§
source§impl Clone for Acceptable
impl Clone for Acceptable
source§fn clone(&self) -> Acceptable
fn clone(&self) -> Acceptable
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Acceptable
impl Debug for Acceptable
source§impl Guard for Acceptable
impl Guard for Acceptable
source§fn check(&self, ctx: &GuardContext<'_>) -> bool
fn check(&self, ctx: &GuardContext<'_>) -> bool
Returns true if predicate condition is met for a given request.
Auto Trait Implementations§
impl Freeze for Acceptable
impl RefUnwindSafe for Acceptable
impl Send for Acceptable
impl Sync for Acceptable
impl Unpin for Acceptable
impl UnwindSafe for Acceptable
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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 more