use actix_web::{HttpResponse, http::header};
use include_dir::{Dir, include_dir};
static DUCKDB_VENDOR: Dir<'_> = include_dir!("$OUT_DIR/duckdb_vendor");
pub(crate) fn serve(path: &str) -> Option<HttpResponse> {
let content_type = mime_guess::from_path(path)
.first_or_octet_stream()
.as_ref()
.to_owned();
if let Some(f) = DUCKDB_VENDOR.get_file(path) {
return Some(
HttpResponse::Ok()
.content_type(content_type)
.insert_header((header::CACHE_CONTROL, "public, max-age=86400"))
.body(f.contents()),
);
}
if let Some(f) = DUCKDB_VENDOR.get_file(format!("{path}.gz")) {
return Some(
HttpResponse::Ok()
.content_type(content_type)
.insert_header((header::CONTENT_ENCODING, "gzip"))
.insert_header((header::CACHE_CONTROL, "public, max-age=86400"))
.body(f.contents()),
);
}
None
}