1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 22:49:21 +02:00

add client websockets support

This commit is contained in:
Nikolay Kim
2019-03-27 18:53:19 -07:00
parent e254fe4f9c
commit c59937784e
19 changed files with 709 additions and 536 deletions

View File

@ -7,7 +7,6 @@ use actix_http::client::Connector;
use actix_http::ws;
use actix_rt::{Runtime, System};
use actix_server::{Server, StreamServiceFactory};
use actix_service::Service;
use awc::{Client, ClientRequest};
use futures::future::{lazy, Future};
use http::Method;
@ -205,16 +204,19 @@ impl TestServerRuntime {
pub fn ws_at(
&mut self,
path: &str,
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, ws::ClientError> {
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError>
{
let url = self.url(path);
let connect = self.client.ws(url).connect();
self.rt
.block_on(lazy(|| ws::Client::default().call(ws::Connect::new(url))))
.block_on(lazy(move || connect.map(|(_, framed)| framed)))
}
/// Connect to a websocket server
pub fn ws(
&mut self,
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, ws::ClientError> {
) -> Result<Framed<impl AsyncRead + AsyncWrite, ws::Codec>, awc::error::WsClientError>
{
self.ws_at("/")
}
}