Struct actix_web::guard::Acceptable
source · pub struct Acceptable { /* private fields */ }
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::{guard::Acceptable, web, HttpResponse};
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
)