diff --git a/src/net/import.rs b/src/net/import.rs index 51627444..6bfe122b 100644 --- a/src/net/import.rs +++ b/src/net/import.rs @@ -38,6 +38,7 @@ async fn handler( "application/json" => Ok(output::json(&res)), "application/cbor" => Ok(output::cbor(&res)), "application/msgpack" => Ok(output::pack(&res)), + "application/octet-stream" => Ok(output::none()), _ => Err(warp::reject::not_found()), }, Err(err) => Err(warp::reject::custom(Error::from(err))), diff --git a/src/net/output.rs b/src/net/output.rs index 38778a84..e233efdf 100644 --- a/src/net/output.rs +++ b/src/net/output.rs @@ -4,18 +4,23 @@ use serde::Serialize; pub enum Output { None, + Fail, Json(Vec), // JSON Cbor(Vec), // CBOR Pack(Vec), // MessagePack } +pub fn none() -> Output { + Output::None +} + pub fn json(val: &T) -> Output where T: Serialize, { match serde_json::to_vec(val) { Ok(v) => Output::Json(v), - Err(_) => Output::None, + Err(_) => Output::Fail, } } @@ -25,7 +30,7 @@ where { match serde_cbor::to_vec(val) { Ok(v) => Output::Cbor(v), - Err(_) => Output::None, + Err(_) => Output::Fail, } } @@ -35,7 +40,7 @@ where { match serde_pack::to_vec(val) { Ok(v) => Output::Pack(v), - Err(_) => Output::None, + Err(_) => Output::Fail, } } @@ -60,7 +65,8 @@ impl warp::Reply for Output { res.headers_mut().insert(CONTENT_TYPE, con); res } - Output::None => StatusCode::INTERNAL_SERVER_ERROR.into_response(), + Output::None => StatusCode::OK.into_response(), + Output::Fail => StatusCode::INTERNAL_SERVER_ERROR.into_response(), } } }