From bf7f4d5381203d5c27b2811d62c5b1781533aa2b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 19 Nov 2025 17:01:36 +0000 Subject: fix some clippy fmt warnings --- src/http/landing.rs | 15 +++++++++------ src/http/mod.rs | 11 +++++------ src/http/websocket.rs | 24 ++++++++++++------------ 3 files changed, 26 insertions(+), 24 deletions(-) (limited to 'src/http') diff --git a/src/http/landing.rs b/src/http/landing.rs index 35e49e5..976ec50 100644 --- a/src/http/landing.rs +++ b/src/http/landing.rs @@ -1,7 +1,6 @@ /// Landing Page Handler -/// +/// /// Serves the HTML landing page or upgrades to WebSocket for Nostr relay connections. - use actix_web::{web, HttpRequest, HttpResponse, Result}; use nostr_relay_builder::LocalRelay; @@ -16,12 +15,16 @@ pub async fn handle( ) -> Result { // Check if this is a WebSocket upgrade request if let Some(upgrade) = req.headers().get("upgrade") { - if upgrade.to_str().unwrap_or("").eq_ignore_ascii_case("websocket") { + if upgrade + .to_str() + .unwrap_or("") + .eq_ignore_ascii_case("websocket") + { // Delegate to WebSocket handler return crate::http::websocket::handle(req, stream, relay).await; } } - + // Otherwise, serve the landing page let html = format!( include_str!("../../templates/landing.html"), @@ -30,8 +33,8 @@ pub async fn handle( domain = config.domain, bind_address = config.bind_address, ); - + Ok(HttpResponse::Ok() .content_type("text/html; charset=utf-8") .body(html)) -} \ No newline at end of file +} diff --git a/src/http/mod.rs b/src/http/mod.rs index 286e8ff..b434c69 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1,7 +1,6 @@ /// HTTP Server Module -/// +/// /// Provides actix-web HTTP server with WebSocket upgrade support for the Nostr relay. - pub mod landing; pub mod websocket; @@ -13,9 +12,9 @@ use crate::config::Config; /// Start the HTTP server with integrated Nostr relay pub async fn run_server(config: Config, relay: LocalRelay) -> anyhow::Result<()> { let bind_addr = config.bind_address.clone(); - + tracing::info!("Starting HTTP server on {}", bind_addr); - + HttpServer::new(move || { App::new() .app_data(web::Data::new(config.clone())) @@ -26,6 +25,6 @@ pub async fn run_server(config: Config, relay: LocalRelay) -> anyhow::Result<()> .bind(&bind_addr)? .run() .await?; - + Ok(()) -} \ No newline at end of file +} diff --git a/src/http/websocket.rs b/src/http/websocket.rs index 7af847a..0171013 100644 --- a/src/http/websocket.rs +++ b/src/http/websocket.rs @@ -1,8 +1,7 @@ /// WebSocket Handler -/// +/// /// Handles WebSocket upgrade requests and passes connections to the Nostr relay. - -use actix_web::{web, HttpRequest, HttpResponse, Result, Error}; +use actix_web::{web, Error, HttpRequest, HttpResponse, Result}; use actix_ws::Message; use futures_util::StreamExt; use nostr_relay_builder::LocalRelay; @@ -14,19 +13,20 @@ pub async fn handle( relay: web::Data, ) -> Result { let (response, mut session, mut msg_stream) = actix_ws::handle(&req, stream)?; - - let peer_addr = req.peer_addr() + + let peer_addr = req + .peer_addr() .unwrap_or_else(|| "0.0.0.0:0".parse().unwrap()); - + tracing::debug!("WebSocket connection from {}", peer_addr); - + // Spawn task to handle the WebSocket connection // TODO: Will use relay.take_connection() for full Nostr relay integration let _relay = relay.get_ref().clone(); actix_web::rt::spawn(async move { // Create a channel to communicate between actix-ws and relay let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); - + // Spawn task to send messages from relay to client let mut session_clone = session.clone(); actix_web::rt::spawn(async move { @@ -36,7 +36,7 @@ pub async fn handle( } } }); - + // Handle incoming messages from client while let Some(Ok(msg)) = msg_stream.next().await { match msg { @@ -65,9 +65,9 @@ pub async fn handle( Message::Nop => {} } } - + tracing::debug!("WebSocket connection closed for {}", peer_addr); }); - + Ok(response) -} \ No newline at end of file +} -- cgit v1.2.3