pub struct TestWebSocket { /* private fields */ }Expand description
The test side of an upgraded connection; see the module docs.
Dropping it ends the connection (the handler’s recv returns an error),
without waiting for the handler.
Implementations§
Source§impl TestWebSocket
impl TestWebSocket
Sourcepub fn handshake(&self) -> &TestResponse
pub fn handshake(&self) -> &TestResponse
The 101 response, for its headers (Sec-WebSocket-Protocol, …).
Sourcepub fn send_text(&mut self, text: &str)
pub fn send_text(&mut self, text: &str)
Send a text message. Panics if the handler’s side is gone.
Sourcepub fn send_binary(&mut self, data: &[u8])
pub fn send_binary(&mut self, data: &[u8])
Send a binary message. Panics if the handler’s side is gone.
Sourcepub fn ping(&mut self, payload: &[u8]) -> Result<(), String>
pub fn ping(&mut self, payload: &[u8]) -> Result<(), String>
Send a ping; the handler’s pong is returned by
recv_frame (and skipped by recv).
Sourcepub fn send(&mut self, frame: Frame) -> Result<(), String>
pub fn send(&mut self, frame: Frame) -> Result<(), String>
Send frame, masked as a client must.
Sourcepub fn send_raw(&mut self, bytes: &[u8]) -> Result<(), String>
pub fn send_raw(&mut self, bytes: &[u8]) -> Result<(), String>
Send bytes as they are — for testing how the handler copes with frames a well-behaved client wouldn’t send (unmasked, bad opcodes).
Sourcepub fn recv_frame(&mut self) -> Result<Frame, String>
pub fn recv_frame(&mut self) -> Result<Frame, String>
The next frame from the handler, waiting at most the timeout. Pings are answered (and returned); nothing is joined.
Sourcepub fn recv(&mut self) -> Result<Option<Message>, String>
pub fn recv(&mut self) -> Result<Option<Message>, String>
The next message from the handler: Ok(None) once it sent a close
frame (answered here, see close_code), Err on
a timeout or when the handler returned without closing. Pings and
pongs are skipped, fragments joined.
Sourcepub fn recv_text(&mut self) -> String
pub fn recv_text(&mut self) -> String
The next message, which must be text. Panics otherwise (binary, a close, a timeout), with what came instead.
Sourcepub fn recv_binary(&mut self) -> Vec<u8> ⓘ
pub fn recv_binary(&mut self) -> Vec<u8> ⓘ
The next message, which must be binary. Panics otherwise.
Sourcepub fn close_code(&self) -> Option<Option<u16>>
pub fn close_code(&self) -> Option<Option<u16>>
The close code the handler sent, once it closed (Some(None) for a
close frame without one).
Sourcepub fn close(self, code: u16, reason: &str) -> Option<u16>
pub fn close(self, code: u16, reason: &str) -> Option<u16>
Run the closing handshake: send a close frame with code and
reason, skip messages until the handler’s close (or the timeout),
then end the connection and wait (at most the timeout) for the
handler to return. Returns the handler’s close code, None when it
didn’t send one.
Sourcepub fn handler_finished(&self, timeout: Duration) -> bool
pub fn handler_finished(&self, timeout: Duration) -> bool
Wait at most timeout for the handler to return; true if it did.
Auto Trait Implementations§
impl !Sync for TestWebSocket
impl Freeze for TestWebSocket
impl RefUnwindSafe for TestWebSocket
impl Send for TestWebSocket
impl Unpin for TestWebSocket
impl UnsafeUnpin for TestWebSocket
impl UnwindSafe for TestWebSocket
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.