mid code commit

This commit is contained in:
zazawowow
2026-01-24 23:18:24 +00:00
parent c293bd9880
commit 1ac70634bd
89 changed files with 1664 additions and 40 deletions

View File

@@ -3,7 +3,6 @@ use crate::config::Config;
use anyhow::Result;
use http_body_util::{BodyExt, Full};
use hyper::body::Bytes;
use hyper::body::Incoming;
use hyper::{Method, Request, Response, StatusCode};
use hyper_util::rt::TokioIo;
use std::sync::Arc;
@@ -25,17 +24,19 @@ impl ApiHandler {
})
}
pub async fn handle_request(
&self,
req: Request<Incoming>,
) -> Result<Response<Full<Bytes>>> {
pub async fn handle_request<B>(&self, req: Request<B>) -> Result<Response<Full<Bytes>>>
where
B: http_body::Body<Data = Bytes> + Send + 'static,
B::Error: std::fmt::Display,
{
let path = req.uri().path();
let method = req.method();
// Convert body to bytes
// Convert Incoming body to bytes using http_body_util::BodyExt
let (parts, body) = req.into_parts();
// hyper::body::Incoming implements http_body::Body, and BodyExt extends it
use http_body_util::BodyExt;
let collected: http_body_util::Collected<Bytes> = body.collect().await
let collected = body.collect().await
.map_err(|_e| anyhow::anyhow!("Failed to read body"))?;
let body_bytes = collected.to_bytes();
@@ -46,10 +47,10 @@ impl ApiHandler {
// Route requests
match (method, path.as_str()) {
(Method::POST, "/rpc/v1") => {
(&Method::POST, "/rpc/v1") => {
self.rpc_handler.handle(req_with_bytes).await
}
(Method::GET, "/health") => {
(&Method::GET, "/health") => {
Ok(Response::builder()
.status(StatusCode::OK)
.body(Full::new(Bytes::from("OK")))