From d4d76d97da9bdf47fedd33434ba476b49146b5ac Mon Sep 17 00:00:00 2001 From: Dominik Werder Date: Tue, 18 May 2021 22:06:47 +0200 Subject: [PATCH] WIP --- disk/src/binned.rs | 13 +++++++++--- disk/src/binnedstream.rs | 17 ++++++++-------- httpret/src/lib.rs | 20 +++++++++++-------- httpret/static/documentation/status-main.html | 2 +- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/disk/src/binned.rs b/disk/src/binned.rs index 3bc8080..2e0a0aa 100644 --- a/disk/src/binned.rs +++ b/disk/src/binned.rs @@ -17,12 +17,15 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; -pub struct BinnedStreamRes { - pub binned_stream: BinnedStream, +pub struct BinnedStreamRes { + pub binned_stream: BinnedStream, pub range: BinnedRange, } -pub async fn binned_stream(node_config: &NodeConfigCached, query: &BinnedQuery) -> Result { +pub async fn binned_stream( + node_config: &NodeConfigCached, + query: &BinnedQuery, +) -> Result>, Error> { if query.channel().backend != node_config.node.backend { let err = Error::with_msg(format!( "backend mismatch node: {} requested: {}", @@ -96,6 +99,10 @@ pub async fn binned_bytes_for_http( node_config: &NodeConfigCached, query: &BinnedQuery, ) -> Result { + // TODO must decide here already which AggKind so that I can call into the generic code. + + todo::todo; + let res = binned_stream(node_config, query).await?; let ret = BinnedBytesForHttpStream::new(res.binned_stream); Ok(Box::pin(ret)) diff --git a/disk/src/binnedstream.rs b/disk/src/binnedstream.rs index f2ec23c..cfecc43 100644 --- a/disk/src/binnedstream.rs +++ b/disk/src/binnedstream.rs @@ -95,21 +95,20 @@ impl Stream for BinnedStreamFromPreBinnedPatches { } } -pub struct BinnedStream { - inp: Pin> + Send>>, +pub struct BinnedStream { + inp: Pin + Send>>, } -impl BinnedStream { - pub fn new( - inp: Pin> + Send>>, - ) -> Result { +impl BinnedStream { + // Item was: Result + pub fn new(inp: Pin + Send>>) -> Result { Ok(Self { inp }) } } -impl Stream for BinnedStream { - // TODO make this generic over all possible things - type Item = Result; +impl Stream for BinnedStream { + //type Item = Result; + type Item = I; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { self.inp.poll_next_unpin(cx) diff --git a/httpret/src/lib.rs b/httpret/src/lib.rs index e8caf10..4f5c640 100644 --- a/httpret/src/lib.rs +++ b/httpret/src/lib.rs @@ -85,16 +85,20 @@ where impl UnwindSafe for Cont {} macro_rules! static_http { - ($path:expr, $tgt:expr, $tgtex:expr) => { + ($path:expr, $tgt:expr, $tgtex:expr, $ctype:expr) => { if $path == concat!("/api/4/documentation/", $tgt) { let c = include_bytes!(concat!("../static/documentation/", $tgtex)); - return Ok(response(StatusCode::OK).body(Body::from(&c[..]))?); + return Ok(response(StatusCode::OK) + .header("content-type", $ctype) + .body(Body::from(&c[..]))?); } }; - ($path:expr, $tgt:expr) => { + ($path:expr, $tgt:expr, $ctype:expr) => { if $path == concat!("/api/4/documentation/", $tgt) { let c = include_bytes!(concat!("../static/documentation/", $tgt)); - return Ok(response(StatusCode::OK).body(Body::from(&c[..]))?); + return Ok(response(StatusCode::OK) + .header("content-type", $ctype) + .body(Body::from(&c[..]))?); } }; } @@ -140,10 +144,10 @@ async fn data_api_proxy_try(req: Request, node_config: &NodeConfigCached) } } else if path.starts_with("/api/4/documentation/") { if req.method() == Method::GET { - static_http!(path, "", "index.html"); - static_http!(path, "style.css"); - static_http!(path, "script.js"); - static_http!(path, "status-main.html"); + static_http!(path, "", "index.html", "text/html"); + static_http!(path, "style.css", "text/stylesheet"); + static_http!(path, "script.js", "text/javascript"); + static_http!(path, "status-main.html", "text/html"); Ok(response(StatusCode::NOT_FOUND).body(Body::empty())?) } else { Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?) diff --git a/httpret/static/documentation/status-main.html b/httpret/static/documentation/status-main.html index 46c046f..da9b9e9 100644 --- a/httpret/static/documentation/status-main.html +++ b/httpret/static/documentation/status-main.html @@ -5,7 +5,7 @@ Main Status - +

daqbuffer - Main Status