From 119b6d049783b3e3a88a8e07923056622cec5f4f Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Mon, 8 Jan 2024 18:36:45 +0300 Subject: [PATCH] save dev state Signed-off-by: onur-ozkan --- main/src/net/http.rs | 6 ++++++ main/src/net/websocket.rs | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/main/src/net/http.rs b/main/src/net/http.rs index f1188ff..e8d13c6 100644 --- a/main/src/net/http.rs +++ b/main/src/net/http.rs @@ -1,3 +1,5 @@ +use crate::websocket::{spawn_proxy, is_websocket_req}; + use super::*; use address_status::{ @@ -240,6 +242,10 @@ async fn router( } }; + if is_websocket_req(&req) { + spawn_proxy("TODO").await.unwrap(); + } + if !remote_addr.ip().is_global() { log::info!( "{}", diff --git a/main/src/net/websocket.rs b/main/src/net/websocket.rs index 2525f41..e5af7cf 100644 --- a/main/src/net/websocket.rs +++ b/main/src/net/websocket.rs @@ -1,11 +1,17 @@ use std::time::Duration; use futures_util::{FutureExt, SinkExt, StreamExt}; +use hyper::{header::HeaderValue, Body, Request}; use log::{error, info}; use tokio::{io, net::TcpListener, sync, time}; use tokio_tungstenite::tungstenite::Message; -async fn spawn_proxy(_addr: &str) -> io::Result<()> { +pub(crate) fn is_websocket_req(req: &Request) -> bool { + let expected = HeaderValue::from_static("websocket"); + Some(&expected) == req.headers().get("upgrade") +} + +pub(crate) async fn spawn_proxy(_addr: &str) -> io::Result<()> { let (tx, _) = sync::broadcast::channel(10); let bind_addr = "127.0.0.1:6678";