Skip to content

Commit

Permalink
fix http server startup (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyangz authored Feb 25, 2025
1 parent 27c816d commit 442af02
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions native-engine/blaze/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait Handler {

pub trait HTTPServer: Send + Sync {
fn start(&self);
fn register_handler(&self, handler: impl Handler + 'static);
fn register_handler(&self, handler: Box<dyn Handler + Send + Sync>);
}

pub struct DefaultHTTPServer {
Expand Down Expand Up @@ -81,26 +81,28 @@ impl HTTPServer for DefaultHTTPServer {
}
}

fn register_handler(&self, handler: impl Handler + 'static) {
fn register_handler(&self, handler: Box<dyn Handler + Send + Sync>) {
let mut handlers = self.handlers.lock().unwrap();
handlers.push(Box::new(handler));
handlers.push(handler);
}
}

pub struct HttpService;
pub struct HttpService {
_server: Box<dyn HTTPServer>,
}

impl HttpService {
pub fn init() -> Self {
let server = DefaultHTTPServer::new();
let server = Box::new(DefaultHTTPServer::new());
#[cfg(feature = "jemalloc-pprof")]
{
use crate::http::pprof::PProfHandler;
server.register_handler(PProfHandler::default());
server.register_handler(Box::new(PProfHandler::default()));

use crate::http::memory_profiling::MemoryProfileHandler;
server.register_handler(MemoryProfileHandler::default());
server.register_handler(Box::new(MemoryProfileHandler::default()));
}
server.start();
Self
Self { _server: server }
}
}

0 comments on commit 442af02

Please sign in to comment.