How to per-message compression in Websockets? #2896
Answered
by
robjtede
yuimarudev
asked this question in
Q&A
-
use actix::{Actor, StreamHandler};
use actix_web::{http::header, web, App, Error, HttpRequest, HttpResponse, HttpServer};
use actix_web_actors::ws;
/// Define HTTP actor
struct MyWs;
impl Actor for MyWs {
type Context = ws::WebsocketContext<Self>;
}
/// Handler for ws::Message message
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
println!("{:?}", msg);
match msg {
Ok(ws::Message::Ping(msg)) => ctx.pong(&msg),
Ok(ws::Message::Text(text)) => ctx.text(text),
Ok(ws::Message::Binary(bin)) => ctx.binary(bin),
_ => (),
}
}
}
async fn index(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
let mut resp = ws::start(MyWs {}, &req, stream)?;
resp.headers_mut().append(header::SEC_WEBSOCKET_EXTENSIONS, header::HeaderValue::from_static("permessage-deflate"));
println!("{:?}", resp);
Ok(resp)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().route("/ws/", web::get().to(index)))
.bind(("0.0.0.0", 65533))?
.run()
.await
} I have tried this and get this error.
Doesn't Actix-web support per-message compression? |
Beta Was this translation helpful? Give feedback.
Answered by
robjtede
Oct 2, 2022
Replies: 2 comments
-
Not yet. Here's the issue for it: #1635 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
robjtede
-
ok thank you |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not yet. Here's the issue for it: #1635