aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/relay_server.rs
diff options
context:
space:
mode:
authorrustdesk <[email protected]>2024-10-07 16:21:36 +0800
committerrustdesk <[email protected]>2024-10-07 16:21:36 +0800
commit6f18a97644cc3176b923ce5a6aad88bec41d6046 (patch)
tree0f0f69445765c31f1bf405eed4b18e6ef2ad031d /src/relay_server.rs
parent3b386b6b5486ed54a09994d1025ed8478127b029 (diff)
downloadrustdesk-server-6f18a97644cc3176b923ce5a6aad88bec41d6046.tar.gz
rustdesk-server-6f18a97644cc3176b923ce5a6aad88bec41d6046.zip
v1.1.121.1.12
Diffstat (limited to 'src/relay_server.rs')
-rw-r--r--src/relay_server.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/relay_server.rs b/src/relay_server.rs
index b55d544..abe6fc2 100644
--- a/src/relay_server.rs
+++ b/src/relay_server.rs
@@ -392,19 +392,30 @@ async fn handle_connection(
async fn make_pair(
stream: TcpStream,
- addr: SocketAddr,
+ mut addr: SocketAddr,
key: &str,
limiter: Limiter,
ws: bool,
) -> ResultType<()> {
if ws {
- make_pair_(
- tokio_tungstenite::accept_async(stream).await?,
- addr,
- key,
- limiter,
- )
- .await;
+ use tokio_tungstenite::tungstenite::handshake::server::{Request, Response};
+ let callback = |req: &Request, response: Response| {
+ let headers = req.headers();
+ let real_ip = headers
+ .get("X-Real-IP")
+ .or_else(|| headers.get("X-Forwarded-For"))
+ .and_then(|header_value| header_value.to_str().ok());
+ if let Some(ip) = real_ip {
+ if ip.contains('.') {
+ addr = format!("{ip}:0").parse().unwrap_or(addr);
+ } else {
+ addr = format!("[{ip}]:0").parse().unwrap_or(addr);
+ }
+ }
+ Ok(response)
+ };
+ let ws_stream = tokio_tungstenite::accept_hdr_async(stream, callback).await?;
+ make_pair_(ws_stream, addr, key, limiter).await;
} else {
make_pair_(FramedStream::from(stream, addr), addr, key, limiter).await;
}