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.