From 5bd48de4185fb670c5c15cb4c046503b66c430c6 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 20 Jul 2024 14:01:24 +0200 Subject: [PATCH] =?UTF-8?q?feat(tvix/nar-bridge):=20add=20404=20handler=20?= =?UTF-8?q?for=20GET/HEAD=20`/nar/=E2=80=A6`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We currently send 405, and that confuses `nix copy`. Send a 404 for now, and add a futurework, as we can actually at least do something more meaningful in case we still have that nar hash in our LRU, which would avoid some unnecessary uploads in some cases. Change-Id: If625e9bd0fd6506cb73b88962d889aa08315fcea Reviewed-on: https://cl.tvl.fyi/c/depot/+/11987 Tested-by: BuildkiteCI Reviewed-by: Brian Olsen --- tvix/nar-bridge/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tvix/nar-bridge/src/lib.rs b/tvix/nar-bridge/src/lib.rs index 5f0e8c19d..46390e865 100644 --- a/tvix/nar-bridge/src/lib.rs +++ b/tvix/nar-bridge/src/lib.rs @@ -1,3 +1,4 @@ +use axum::http::StatusCode; use axum::routing::{head, put}; use axum::{routing::get, Router}; use lru::LruCache; @@ -50,6 +51,10 @@ impl AppState { pub fn gen_router(priority: u64) -> Router { Router::new() .route("/", get(root)) + // FUTUREWORK: respond for NARs that we still have in root_nodes (at least HEAD) + // This avoids some unnecessary NAR uploading from multiple concurrent clients, and is cheap. + .route("/nar/:nar_str", get(four_o_four)) + .route("/nar/:nar_str", head(four_o_four)) .route("/nar/:nar_str", put(nar::put)) .route("/nar/tvix-castore/:root_node_enc", get(nar::get)) .route("/:narinfo_str", get(narinfo::get)) @@ -61,6 +66,10 @@ async fn root() -> &'static str { "Hello from nar-bridge" } +async fn four_o_four() -> Result<(), StatusCode> { + Err(StatusCode::NOT_FOUND) +} + async fn nix_cache_info(priority: u64) -> String { format!( "StoreDir: /nix/store\nWantMassQuery: 1\nPriority: {}\n",