mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
Replace flate2-xxx features with compress
This commit is contained in:
@ -3,26 +3,17 @@ use std::io;
|
||||
use actix_codec::Framed;
|
||||
use actix_http::{body::BodySize, h1, ws, Error, HttpService, Request, Response};
|
||||
use actix_http_test::TestServer;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use bytes::Bytes;
|
||||
use futures::future::ok;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
|
||||
async fn ws_service(req: ws::Frame) -> Result<ws::Message, io::Error> {
|
||||
match req {
|
||||
ws::Frame::Ping(msg) => Ok(ws::Message::Pong(msg)),
|
||||
ws::Frame::Text(text) => {
|
||||
let text = if let Some(pl) = text {
|
||||
String::from_utf8(Vec::from(pl.as_ref())).unwrap()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
Ok(ws::Message::Text(text))
|
||||
}
|
||||
ws::Frame::Binary(bin) => Ok(ws::Message::Binary(
|
||||
bin.map(|e| e.freeze())
|
||||
.unwrap_or_else(|| Bytes::from(""))
|
||||
.into(),
|
||||
ws::Frame::Text(text) => Ok(ws::Message::Text(
|
||||
String::from_utf8(Vec::from(text.as_ref())).unwrap(),
|
||||
)),
|
||||
ws::Frame::Binary(bin) => Ok(ws::Message::Binary(bin)),
|
||||
ws::Frame::Close(reason) => Ok(ws::Message::Close(reason)),
|
||||
_ => Ok(ws::Message::Close(None)),
|
||||
}
|
||||
@ -56,14 +47,14 @@ async fn test_simple() {
|
||||
.await
|
||||
.unwrap();
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
assert_eq!(item, ws::Frame::Text(Some(BytesMut::from("text"))));
|
||||
assert_eq!(item, ws::Frame::Text(Bytes::from_static(b"text")));
|
||||
|
||||
framed
|
||||
.send(ws::Message::Binary("text".into()))
|
||||
.await
|
||||
.unwrap();
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
assert_eq!(item, ws::Frame::Binary(Some(BytesMut::from(&b"text"[..]))));
|
||||
assert_eq!(item, ws::Frame::Binary(Bytes::from_static(b"text")));
|
||||
|
||||
framed.send(ws::Message::Ping("text".into())).await.unwrap();
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
|
Reference in New Issue
Block a user