From 1d6d986e1349ac10f64bdb96bbc5842279f0c51c Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Tue, 5 Feb 2019 04:21:56 +0100 Subject: [PATCH] Fix Chrome connection issue introduced with switch to tungstenite Chrome requires the subprotocol to be "binary", FF doesn't seem to care (for some reason?). --- src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6a105d8..04cba80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,8 @@ use tokio::net::TcpStream; use tokio_codec::Decoder; use tokio_core::reactor::Core; use tokio_tls::TlsConnector; -use tokio_tungstenite::accept_async_with_config; +use tokio_tungstenite::accept_hdr_async_with_config; +use tungstenite::handshake::server::Request; use tungstenite::protocol::Message; use tungstenite::protocol::WebSocketConfig; @@ -110,7 +111,16 @@ fn main() { max_message_size: Some(0x7f_ffff), // maximum size accepted by Murmur max_frame_size: Some(0x7f_ffff), // maximum size accepted by Murmur }; - let client = accept_async_with_config(client, Some(websocket_config)).from_err(); + fn header_callback( + _req: &Request, + ) -> tungstenite::error::Result>> { + Ok(Some(vec![( + "Sec-WebSocket-Protocol".to_string(), + "binary".to_string(), + )])) + } + let client = accept_hdr_async_with_config(client, header_callback, Some(websocket_config)) + .from_err(); // Once both are done, begin proxy duty let f = client