pub struct WebSocketUpgrade { /* private fields */ }Expand description
Represents a validated WebSocket upgrade request.
This struct is returned after validating both authentication and origin, indicating that the WebSocket upgrade can proceed safely.
§Example
ⓘ
use actix_security::http::security::websocket::{WebSocketSecurityConfig, WebSocketUpgrade};
let config = WebSocketSecurityConfig::new()
.allowed_origins(vec!["https://myapp.com".into()])
.require_authentication(true);
#[get("/ws")]
async fn ws_handler(
req: HttpRequest,
stream: web::Payload,
config: web::Data<WebSocketSecurityConfig>,
) -> Result<HttpResponse, actix_web::Error> {
// Validates auth and origin in one step
let upgrade = config.validate_upgrade(&req)?;
// Access the user
let user = upgrade.user();
// Proceed with upgrade
let resp = actix_ws::start(MyActor::new(user.clone()), &req, stream)?;
Ok(resp)
}Implementations§
Source§impl WebSocketUpgrade
impl WebSocketUpgrade
Sourcepub fn new(user: Option<User>, origin: Option<String>) -> WebSocketUpgrade
pub fn new(user: Option<User>, origin: Option<String>) -> WebSocketUpgrade
Creates a new WebSocketUpgrade.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Returns true if the request came from an authenticated user.
Trait Implementations§
Source§impl Clone for WebSocketUpgrade
impl Clone for WebSocketUpgrade
Source§fn clone(&self) -> WebSocketUpgrade
fn clone(&self) -> WebSocketUpgrade
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 moreAuto Trait Implementations§
impl Freeze for WebSocketUpgrade
impl RefUnwindSafe for WebSocketUpgrade
impl Send for WebSocketUpgrade
impl Sync for WebSocketUpgrade
impl Unpin for WebSocketUpgrade
impl UnwindSafe for WebSocketUpgrade
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