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
3 changes: 3 additions & 0 deletions src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};

use actix_web::http::StatusCode;
use bytes::Bytes;
use futures_util::StreamExt;
use reqwest::{Client, Response};
Expand Down Expand Up @@ -325,6 +326,8 @@ async fn download_payload(client: &Client, url: Url, config: &Config) -> Result<
let response = client.get(url).send().await?;
let status = response.status();
if !status.is_success() {
let status =
StatusCode::from_u16(status.as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
return Err(Error::Http(status));
}

Expand Down
15 changes: 13 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::result;

use actix_web::ResponseError;
use actix_web::http::StatusCode;
use thiserror::Error;

type PutObjectSdkError =
Expand All @@ -23,7 +24,7 @@ pub enum Error {
#[error("Reqwest Error {0}")]
Reqwest(#[from] reqwest::Error),
#[error("HTTP Error {0}")]
Http(reqwest::StatusCode),
Http(StatusCode),
#[error("{0}")]
Custom(String),
#[error("Too Large")]
Expand All @@ -40,7 +41,17 @@ pub enum Error {
Timeout,
}

impl ResponseError for Error {}
impl ResponseError for Error {
fn status_code(&self) -> StatusCode {
match self {
Self::Reqwest(err) if err.is_connect() => StatusCode::BAD_GATEWAY,
Self::Reqwest(err) if err.is_timeout() => StatusCode::GATEWAY_TIMEOUT,
Self::Http(status) => *status,
Self::InvalidRequest => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}

// Fix clippy "the `Err`-variant returned from this function is very large"
impl From<PutObjectSdkError> for Error {
Expand Down
28 changes: 19 additions & 9 deletions src/repos.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::LazyLock;

use actix_web::http::{Method, Uri};
use actix_web::http::{Method, StatusCode, Uri};
use actix_web::{HttpResponse, Route, guard, web};
use regex::Regex;

Expand Down Expand Up @@ -464,18 +464,28 @@ pub fn nix_intel(
}

if task.path.starts_with("nar/") || task.path.ends_with(".narinfo") {
Ok(task
match task
.resolve(&intel_mission, &config)
.await?
.reverse_proxy(&intel_mission)
.await?
.into())
.await
{
Ok(resp) => Ok(resp.into()),
Err(Error::Http(status)) if status == StatusCode::NOT_FOUND => {
Ok(HttpResponse::NotFound().finish().into())
}
Err(Error::Reqwest(_)) => Ok(HttpResponse::NotFound().finish().into()),
Err(e) => Err(e),
}
} else if task.path == "nix-cache-info" {
Ok(task
.resolve_upstream()
.reverse_proxy(&intel_mission)
.await?
.into())
match task.resolve_upstream().reverse_proxy(&intel_mission).await {
Ok(resp) => Ok(resp.into()),
Err(Error::Http(status)) if status == StatusCode::NOT_FOUND => {
Ok(HttpResponse::NotFound().finish().into())
}
Err(Error::Reqwest(_)) => Ok(HttpResponse::NotFound().finish().into()),
Err(e) => Err(e),
}
} else {
Ok(Redirect::Permanent(task.upstream_url().to_string()).into())
}
Expand Down