Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ license = "MIT"
axum = "0.8"
tokio = { version = "1", features = ["full", "signal"] }
tokio-util = { version = "0.7", features = ["io"] }
tokio-stream = "0.1"
bytes = "1"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2"
Expand Down
1 change: 0 additions & 1 deletion src/routes/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub async fn handle_remove(
let removed = action_service.mark_completed(&mac)?;

if removed {
tracing::info!("Marked MAC {} as completed", mac);
Ok((StatusCode::OK, "OK").into_response())
} else {
tracing::warn!("MAC {} not found in action.cfg", mac);
Expand Down
20 changes: 12 additions & 8 deletions src/routes/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use axum::http::{HeaderMap, StatusCode, header};
use axum::response::Response;
use serde::Deserialize;
use tokio::fs::File;
use tokio_stream::wrappers::ReceiverStream;
use tokio_util::io::ReaderStream;

/// Query parameters for the ISO endpoint.
Expand Down Expand Up @@ -180,10 +181,11 @@ async fn serve_template(
.unwrap())
}

/// Serve a file from within the ISO.
/// Serve a file from within the ISO using streaming.
fn serve_from_iso(iso_service: &IsoService, iso_name: &str, path: &str) -> AppResult<Response> {
let content = iso_service.read_from_iso(iso_name, path)?;
let content_length = content.len();
let (content_length, receiver) = iso_service.stream_from_iso(iso_name, path)?;
let stream = ReceiverStream::new(receiver);
let body = Body::from_stream(stream);

// Determine content type based on file extension
let content_type = guess_content_type(path);
Expand All @@ -192,11 +194,11 @@ fn serve_from_iso(iso_service: &IsoService, iso_name: &str, path: &str) -> AppRe
.status(StatusCode::OK)
.header(header::CONTENT_TYPE, content_type)
.header(header::CONTENT_LENGTH, content_length)
.body(Body::from(content))
.body(body)
.unwrap())
}

/// Serve initrd with firmware concatenated.
/// Serve initrd with firmware concatenated using streaming.
///
/// Used for Debian netboot where firmware.cpio.gz needs to be appended to initrd.
fn serve_initrd_with_firmware(
Expand All @@ -205,14 +207,16 @@ fn serve_initrd_with_firmware(
initrd_path: &str,
firmware: &str,
) -> AppResult<Response> {
let content = iso_service.read_initrd_with_firmware(iso_name, initrd_path, firmware)?;
let content_length = content.len();
let (content_length, receiver) =
iso_service.stream_initrd_with_firmware(iso_name, initrd_path, firmware)?;
let stream = ReceiverStream::new(receiver);
let body = Body::from_stream(stream);

Ok(Response::builder()
.status(StatusCode::OK)
.header(header::CONTENT_TYPE, "application/octet-stream")
.header(header::CONTENT_LENGTH, content_length)
.body(Body::from(content))
.body(body)
.unwrap())
}

Expand Down
Loading