diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-21 04:44:40 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-21 04:44:40 +0000 |
| commit | 7dda553918705277c7fa5b903c6a40e4b4a0aa8d (patch) | |
| tree | 4f3511cd3fe56928bd2aa9a22f4ddd592f4c6b83 /src/http/mod.rs | |
| parent | 2e799fa7ec57d284c643df8b8dc54471470f5c59 (diff) | |
add nip11
Diffstat (limited to 'src/http/mod.rs')
| -rw-r--r-- | src/http/mod.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 4690790..7c0e7bb 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | /// | 2 | /// |
| 3 | /// Provides hyper HTTP server with WebSocket upgrade support for the Nostr relay. | 3 | /// Provides hyper HTTP server with WebSocket upgrade support for the Nostr relay. |
| 4 | pub mod landing; | 4 | pub mod landing; |
| 5 | pub mod nip11; | ||
| 5 | 6 | ||
| 6 | use std::future::Future; | 7 | use std::future::Future; |
| 7 | use std::net::SocketAddr; | 8 | use std::net::SocketAddr; |
| @@ -46,6 +47,32 @@ impl Service<Request<Incoming>> for HttpService { | |||
| 46 | fn call(&self, req: Request<Incoming>) -> Self::Future { | 47 | fn call(&self, req: Request<Incoming>) -> Self::Future { |
| 47 | let base = Response::builder().header("server", "ngit-grasp"); | 48 | let base = Response::builder().header("server", "ngit-grasp"); |
| 48 | 49 | ||
| 50 | // Check for NIP-11 relay information request (Accept: application/nostr+json) | ||
| 51 | if let Some(accept) = req.headers().get("accept") { | ||
| 52 | if accept | ||
| 53 | .to_str() | ||
| 54 | .map(|s| s.contains("application/nostr+json")) | ||
| 55 | .unwrap_or(false) | ||
| 56 | { | ||
| 57 | let doc = nip11::RelayInformationDocument::from_config(&self.config); | ||
| 58 | let json = doc.to_json().unwrap_or_else(|e| { | ||
| 59 | tracing::error!("Failed to serialize NIP-11 document: {}", e); | ||
| 60 | "{}".to_string() | ||
| 61 | }); | ||
| 62 | |||
| 63 | tracing::debug!("Serving NIP-11 relay information document to {}", self.remote); | ||
| 64 | |||
| 65 | return Box::pin(async move { | ||
| 66 | Ok(base | ||
| 67 | .status(200) | ||
| 68 | .header("content-type", "application/nostr+json") | ||
| 69 | .header("access-control-allow-origin", "*") | ||
| 70 | .body(json) | ||
| 71 | .unwrap()) | ||
| 72 | }); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 49 | // Check if this is a WebSocket upgrade request | 76 | // Check if this is a WebSocket upgrade request |
| 50 | if let (Some(c), Some(w)) = ( | 77 | if let (Some(c), Some(w)) = ( |
| 51 | req.headers().get("connection"), | 78 | req.headers().get("connection"), |