diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-19 17:01:36 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-19 17:01:36 +0000 |
| commit | bf7f4d5381203d5c27b2811d62c5b1781533aa2b (patch) | |
| tree | 26903bbf535d83abd7242370d8b6932eb80e3389 /src/http | |
| parent | fa065ad128882755f2a988d6203b59a2ab5e38ff (diff) | |
fix some clippy fmt warnings
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/landing.rs | 15 | ||||
| -rw-r--r-- | src/http/mod.rs | 11 | ||||
| -rw-r--r-- | src/http/websocket.rs | 24 |
3 files changed, 26 insertions, 24 deletions
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 @@ | |||
| 1 | /// Landing Page Handler | 1 | /// Landing Page Handler |
| 2 | /// | 2 | /// |
| 3 | /// Serves the HTML landing page or upgrades to WebSocket for Nostr relay connections. | 3 | /// Serves the HTML landing page or upgrades to WebSocket for Nostr relay connections. |
| 4 | |||
| 5 | use actix_web::{web, HttpRequest, HttpResponse, Result}; | 4 | use actix_web::{web, HttpRequest, HttpResponse, Result}; |
| 6 | use nostr_relay_builder::LocalRelay; | 5 | use nostr_relay_builder::LocalRelay; |
| 7 | 6 | ||
| @@ -16,12 +15,16 @@ pub async fn handle( | |||
| 16 | ) -> Result<HttpResponse> { | 15 | ) -> Result<HttpResponse> { |
| 17 | // Check if this is a WebSocket upgrade request | 16 | // Check if this is a WebSocket upgrade request |
| 18 | if let Some(upgrade) = req.headers().get("upgrade") { | 17 | if let Some(upgrade) = req.headers().get("upgrade") { |
| 19 | if upgrade.to_str().unwrap_or("").eq_ignore_ascii_case("websocket") { | 18 | if upgrade |
| 19 | .to_str() | ||
| 20 | .unwrap_or("") | ||
| 21 | .eq_ignore_ascii_case("websocket") | ||
| 22 | { | ||
| 20 | // Delegate to WebSocket handler | 23 | // Delegate to WebSocket handler |
| 21 | return crate::http::websocket::handle(req, stream, relay).await; | 24 | return crate::http::websocket::handle(req, stream, relay).await; |
| 22 | } | 25 | } |
| 23 | } | 26 | } |
| 24 | 27 | ||
| 25 | // Otherwise, serve the landing page | 28 | // Otherwise, serve the landing page |
| 26 | let html = format!( | 29 | let html = format!( |
| 27 | include_str!("../../templates/landing.html"), | 30 | include_str!("../../templates/landing.html"), |
| @@ -30,8 +33,8 @@ pub async fn handle( | |||
| 30 | domain = config.domain, | 33 | domain = config.domain, |
| 31 | bind_address = config.bind_address, | 34 | bind_address = config.bind_address, |
| 32 | ); | 35 | ); |
| 33 | 36 | ||
| 34 | Ok(HttpResponse::Ok() | 37 | Ok(HttpResponse::Ok() |
| 35 | .content_type("text/html; charset=utf-8") | 38 | .content_type("text/html; charset=utf-8") |
| 36 | .body(html)) | 39 | .body(html)) |
| 37 | } \ No newline at end of file | 40 | } |
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 @@ | |||
| 1 | /// HTTP Server Module | 1 | /// HTTP Server Module |
| 2 | /// | 2 | /// |
| 3 | /// Provides actix-web HTTP server with WebSocket upgrade support for the Nostr relay. | 3 | /// Provides actix-web HTTP server with WebSocket upgrade support for the Nostr relay. |
| 4 | |||
| 5 | pub mod landing; | 4 | pub mod landing; |
| 6 | pub mod websocket; | 5 | pub mod websocket; |
| 7 | 6 | ||
| @@ -13,9 +12,9 @@ use crate::config::Config; | |||
| 13 | /// Start the HTTP server with integrated Nostr relay | 12 | /// Start the HTTP server with integrated Nostr relay |
| 14 | pub async fn run_server(config: Config, relay: LocalRelay) -> anyhow::Result<()> { | 13 | pub async fn run_server(config: Config, relay: LocalRelay) -> anyhow::Result<()> { |
| 15 | let bind_addr = config.bind_address.clone(); | 14 | let bind_addr = config.bind_address.clone(); |
| 16 | 15 | ||
| 17 | tracing::info!("Starting HTTP server on {}", bind_addr); | 16 | tracing::info!("Starting HTTP server on {}", bind_addr); |
| 18 | 17 | ||
| 19 | HttpServer::new(move || { | 18 | HttpServer::new(move || { |
| 20 | App::new() | 19 | App::new() |
| 21 | .app_data(web::Data::new(config.clone())) | 20 | .app_data(web::Data::new(config.clone())) |
| @@ -26,6 +25,6 @@ pub async fn run_server(config: Config, relay: LocalRelay) -> anyhow::Result<()> | |||
| 26 | .bind(&bind_addr)? | 25 | .bind(&bind_addr)? |
| 27 | .run() | 26 | .run() |
| 28 | .await?; | 27 | .await?; |
| 29 | 28 | ||
| 30 | Ok(()) | 29 | Ok(()) |
| 31 | } \ No newline at end of file | 30 | } |
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 @@ | |||
| 1 | /// WebSocket Handler | 1 | /// WebSocket Handler |
| 2 | /// | 2 | /// |
| 3 | /// Handles WebSocket upgrade requests and passes connections to the Nostr relay. | 3 | /// Handles WebSocket upgrade requests and passes connections to the Nostr relay. |
| 4 | 4 | use actix_web::{web, Error, HttpRequest, HttpResponse, Result}; | |
| 5 | use actix_web::{web, HttpRequest, HttpResponse, Result, Error}; | ||
| 6 | use actix_ws::Message; | 5 | use actix_ws::Message; |
| 7 | use futures_util::StreamExt; | 6 | use futures_util::StreamExt; |
| 8 | use nostr_relay_builder::LocalRelay; | 7 | use nostr_relay_builder::LocalRelay; |
| @@ -14,19 +13,20 @@ pub async fn handle( | |||
| 14 | relay: web::Data<LocalRelay>, | 13 | relay: web::Data<LocalRelay>, |
| 15 | ) -> Result<HttpResponse, Error> { | 14 | ) -> Result<HttpResponse, Error> { |
| 16 | let (response, mut session, mut msg_stream) = actix_ws::handle(&req, stream)?; | 15 | let (response, mut session, mut msg_stream) = actix_ws::handle(&req, stream)?; |
| 17 | 16 | ||
| 18 | let peer_addr = req.peer_addr() | 17 | let peer_addr = req |
| 18 | .peer_addr() | ||
| 19 | .unwrap_or_else(|| "0.0.0.0:0".parse().unwrap()); | 19 | .unwrap_or_else(|| "0.0.0.0:0".parse().unwrap()); |
| 20 | 20 | ||
| 21 | tracing::debug!("WebSocket connection from {}", peer_addr); | 21 | tracing::debug!("WebSocket connection from {}", peer_addr); |
| 22 | 22 | ||
| 23 | // Spawn task to handle the WebSocket connection | 23 | // Spawn task to handle the WebSocket connection |
| 24 | // TODO: Will use relay.take_connection() for full Nostr relay integration | 24 | // TODO: Will use relay.take_connection() for full Nostr relay integration |
| 25 | let _relay = relay.get_ref().clone(); | 25 | let _relay = relay.get_ref().clone(); |
| 26 | actix_web::rt::spawn(async move { | 26 | actix_web::rt::spawn(async move { |
| 27 | // Create a channel to communicate between actix-ws and relay | 27 | // Create a channel to communicate between actix-ws and relay |
| 28 | let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); | 28 | let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); |
| 29 | 29 | ||
| 30 | // Spawn task to send messages from relay to client | 30 | // Spawn task to send messages from relay to client |
| 31 | let mut session_clone = session.clone(); | 31 | let mut session_clone = session.clone(); |
| 32 | actix_web::rt::spawn(async move { | 32 | actix_web::rt::spawn(async move { |
| @@ -36,7 +36,7 @@ pub async fn handle( | |||
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | }); | 38 | }); |
| 39 | 39 | ||
| 40 | // Handle incoming messages from client | 40 | // Handle incoming messages from client |
| 41 | while let Some(Ok(msg)) = msg_stream.next().await { | 41 | while let Some(Ok(msg)) = msg_stream.next().await { |
| 42 | match msg { | 42 | match msg { |
| @@ -65,9 +65,9 @@ pub async fn handle( | |||
| 65 | Message::Nop => {} | 65 | Message::Nop => {} |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | tracing::debug!("WebSocket connection closed for {}", peer_addr); | 69 | tracing::debug!("WebSocket connection closed for {}", peer_addr); |
| 70 | }); | 70 | }); |
| 71 | 71 | ||
| 72 | Ok(response) | 72 | Ok(response) |
| 73 | } \ No newline at end of file | 73 | } |