hyperlane-plugin-websocket 23.2.0

A WebSocket plugin for the Hyperlane framework, providing robust WebSocket communication capabilities and integrating with hyperlane-broadcast for efficient message dissemination.
Documentation
use super::*;

impl Transport for TestWsTransport {
    fn peer_addr(&self) -> io::Result<SocketAddr> {
        Err(io::ErrorKind::AddrNotAvailable.into())
    }

    fn local_addr(&self) -> io::Result<SocketAddr> {
        Err(io::ErrorKind::AddrNotAvailable.into())
    }
}

impl AsyncRead for TestWsTransport {
    fn poll_read(
        mut self: Pin<&mut Self>,
        cx: &mut task::Context<'_>,
        buf: &mut ReadBuf<'_>,
    ) -> Poll<io::Result<()>> {
        Pin::new(&mut self.0).poll_read(cx, buf)
    }
}

impl AsyncWrite for TestWsTransport {
    fn poll_write(
        mut self: Pin<&mut Self>,
        cx: &mut task::Context<'_>,
        buf: &[u8],
    ) -> Poll<io::Result<usize>> {
        Pin::new(&mut self.0).poll_write(cx, buf)
    }

    fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
        Pin::new(&mut self.0).poll_flush(cx)
    }

    fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
        Pin::new(&mut self.0).poll_shutdown(cx)
    }
}

impl ServerHook for TestWsContinueHook {
    async fn new(_stream: &mut Stream, _ctx: &mut Context) -> Self {
        Self
    }

    async fn handle(self, _stream: &mut Stream, _ctx: &mut Context) -> Status {
        Status::Continue
    }
}

impl ServerHook for TestWsEchoHook {
    async fn new(_stream: &mut Stream, _ctx: &mut Context) -> Self {
        Self
    }

    async fn handle(self, _stream: &mut Stream, ctx: &mut Context) -> Status {
        let body: Vec<u8> = ctx.get_request().get_body().clone();
        ctx.get_mut_response().set_body(body);
        Status::Continue
    }
}