pub struct OriginValidator { /* private fields */ }Expand description
Validates the Origin header of WebSocket upgrade requests.
§Spring Security Equivalent
Spring’s StompSubProtocolErrorHandler combined with AllowedOriginPatterns
§Example
ⓘ
use actix_security::http::security::websocket::OriginValidator;
let validator = OriginValidator::new(&["https://myapp.com"]);
#[get("/ws")]
async fn ws_handler(req: HttpRequest) -> Result<HttpResponse, Error> {
validator.validate(&req)?;
// ... upgrade to WebSocket
}Implementations§
Source§impl OriginValidator
impl OriginValidator
Sourcepub fn builder() -> OriginValidatorBuilder
pub fn builder() -> OriginValidatorBuilder
Creates a builder for more complex configuration.
Sourcepub fn allow_any() -> Self
pub fn allow_any() -> Self
Creates a validator that allows any origin.
§Warning
This is dangerous and should only be used for development or when you have other authentication mechanisms in place.
Sourcepub fn validate(&self, req: &HttpRequest) -> Result<(), WebSocketSecurityError>
pub fn validate(&self, req: &HttpRequest) -> Result<(), WebSocketSecurityError>
Validates the Origin header of the request.
§Errors
WebSocketSecurityError::MissingOrigin- If Origin header is missing andallow_missingis falseWebSocketSecurityError::InvalidOrigin- If Origin is not in the allowed list
Trait Implementations§
Source§impl Clone for OriginValidator
impl Clone for OriginValidator
Source§fn clone(&self) -> OriginValidator
fn clone(&self) -> OriginValidator
Returns a duplicate 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 OriginValidator
impl Debug for OriginValidator
Source§impl Default for OriginValidator
impl Default for OriginValidator
Source§fn default() -> OriginValidator
fn default() -> OriginValidator
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for OriginValidator
impl RefUnwindSafe for OriginValidator
impl Send for OriginValidator
impl Sync for OriginValidator
impl Unpin for OriginValidator
impl UnwindSafe for OriginValidator
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§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