Skip to content

Commit af4225e

Browse files
committed
add support for header-only responses
1 parent d3c46f7 commit af4225e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/render.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::templates::SplitTemplate;
22
use crate::AppState;
33
use actix_web::http::StatusCode;
4-
use actix_web::HttpResponseBuilder;
4+
use actix_web::{HttpResponse, HttpResponseBuilder};
55
use anyhow::{bail, format_err, Context as AnyhowContext};
66
use async_recursion::async_recursion;
77
use handlebars::{BlockContext, Context, JsonValue, RenderError, Renderable};
@@ -86,6 +86,11 @@ impl<W: std::io::Write> HeaderContext<W> {
8686
http_response,
8787
})
8888
}
89+
90+
pub async fn close(mut self) -> anyhow::Result<(RenderContext<W>, HttpResponse)> {
91+
let renderer = RenderContext::new(self.app_state, self.writer, JsonValue::Null).await?;
92+
Ok((renderer, self.response.finish()))
93+
}
8994
}
9095

9196
fn get_object_str<'a>(json: &'a JsonValue, key: &str) -> Option<&'a str> {

src/webserver/http.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,16 @@ async fn build_response_header_and_stream<S: Stream<Item = DbItem>>(
185185
}
186186
}
187187
}
188-
Err(ErrorInternalServerError("no SQL statements to execute"))
188+
log::debug!("No SQL statements left to execute for the body of the response");
189+
let (renderer, http_response) = head_context
190+
.close()
191+
.await
192+
.map_err(ErrorInternalServerError)?;
193+
Ok(ResponseWithWriter {
194+
http_response,
195+
renderer,
196+
database_entries_stream: stream,
197+
})
189198
}
190199

191200
struct ResponseWithWriter<S> {

0 commit comments

Comments
 (0)