From 8a43ede301bafda25346d71c24fa23d1d0c78f57 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Sat, 27 Nov 2021 15:56:02 +0100 Subject: [PATCH] add range header on 416 on web request --- src/api/error.rs | 1 + src/web/error.rs | 11 ++++++++++- src/web/web_server.rs | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/api/error.rs b/src/api/error.rs index 3be7d682..4ad8ef82 100644 --- a/src/api/error.rs +++ b/src/api/error.rs @@ -134,6 +134,7 @@ impl Error { pub fn add_headers(&self, header_map: &mut HeaderMap) { use hyper::header; + #[allow(clippy::single_match)] match self { Error::InvalidRange((_, len)) => { header_map.append( diff --git a/src/web/error.rs b/src/web/error.rs index 426155c1..55990e9d 100644 --- a/src/web/error.rs +++ b/src/web/error.rs @@ -1,5 +1,6 @@ use err_derive::Error; -use hyper::StatusCode; +use hyper::header::HeaderValue; +use hyper::{HeaderMap, StatusCode}; use garage_util::error::Error as GarageError; @@ -47,4 +48,12 @@ impl Error { _ => StatusCode::BAD_REQUEST, } } + + pub fn add_headers(&self, header_map: &mut HeaderMap) { + #[allow(clippy::single_match)] + match self { + Error::ApiError(e) => e.add_headers(header_map), + _ => (), + } + } } diff --git a/src/web/web_server.rs b/src/web/web_server.rs index e9c5039d..4a603c05 100644 --- a/src/web/web_server.rs +++ b/src/web/web_server.rs @@ -62,6 +62,7 @@ fn error_to_res(e: Error) -> Response { let body: Body = Body::from(format!("{}\n", e)); let mut http_error = Response::new(body); *http_error.status_mut() = e.http_status_code(); + e.add_headers(http_error.headers_mut()); http_error }