Skip to content

Commit

Permalink
Add HEAD request to /download (Fix TalRoni#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Aug 1, 2024
1 parent 5f4ca86 commit 393ee4e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ pub async fn serve(root: &Path, binding: impl Into<ServerBinding>, server_addr:
path.parse::<Uri>().map(warp::redirect).unwrap()
})
.with(warp::trace::request());
let download_head = warp::head()
.and(warp::path("api"))
.and(warp::path("v1"))
.and(warp::path("crates"))
.and(warp::path::param())
.and(warp::path::param())
.and(warp::path("download"))
.map(move |name: String, version: String| {
let crate_path = crate_path(&name).join(crate_file_name(&name, &version));
let path = format!(
"/crates/{}",
crate_path
.components()
.map(|c| format!("{}", c.as_os_str().to_str().unwrap()))
.join("/")
);

// TODO: Ideally we shouldn't unwrap here. That's not that easily
// possible, though, because then we'd need to handle errors
// and we can't use the response function because it will
// overwrite the HTTP status even on success.
path.parse::<Uri>().map(warp::redirect).unwrap()
})
.with(warp::trace::request());
let publish = warp::put()
.and(warp::path("api"))
.and(warp::path("v1"))
Expand Down Expand Up @@ -210,6 +234,7 @@ pub async fn serve(root: &Path, binding: impl Into<ServerBinding>, server_addr:
let routes = frontend
.or(crates)
.or(download)
.or(download_head)
.or(publish)
.or(dist_dir)
.or(rustup_dir)
Expand Down

0 comments on commit 393ee4e

Please sign in to comment.