Allow ‘application/octet-stream’ content-type when importing
This commit is contained in:
parent
527361efd4
commit
187d9c08dc
2 changed files with 11 additions and 4 deletions
|
@ -38,6 +38,7 @@ async fn handler(
|
||||||
"application/json" => Ok(output::json(&res)),
|
"application/json" => Ok(output::json(&res)),
|
||||||
"application/cbor" => Ok(output::cbor(&res)),
|
"application/cbor" => Ok(output::cbor(&res)),
|
||||||
"application/msgpack" => Ok(output::pack(&res)),
|
"application/msgpack" => Ok(output::pack(&res)),
|
||||||
|
"application/octet-stream" => Ok(output::none()),
|
||||||
_ => Err(warp::reject::not_found()),
|
_ => Err(warp::reject::not_found()),
|
||||||
},
|
},
|
||||||
Err(err) => Err(warp::reject::custom(Error::from(err))),
|
Err(err) => Err(warp::reject::custom(Error::from(err))),
|
||||||
|
|
|
@ -4,18 +4,23 @@ use serde::Serialize;
|
||||||
|
|
||||||
pub enum Output {
|
pub enum Output {
|
||||||
None,
|
None,
|
||||||
|
Fail,
|
||||||
Json(Vec<u8>), // JSON
|
Json(Vec<u8>), // JSON
|
||||||
Cbor(Vec<u8>), // CBOR
|
Cbor(Vec<u8>), // CBOR
|
||||||
Pack(Vec<u8>), // MessagePack
|
Pack(Vec<u8>), // MessagePack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn none() -> Output {
|
||||||
|
Output::None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn json<T>(val: &T) -> Output
|
pub fn json<T>(val: &T) -> Output
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
match serde_json::to_vec(val) {
|
match serde_json::to_vec(val) {
|
||||||
Ok(v) => Output::Json(v),
|
Ok(v) => Output::Json(v),
|
||||||
Err(_) => Output::None,
|
Err(_) => Output::Fail,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +30,7 @@ where
|
||||||
{
|
{
|
||||||
match serde_cbor::to_vec(val) {
|
match serde_cbor::to_vec(val) {
|
||||||
Ok(v) => Output::Cbor(v),
|
Ok(v) => Output::Cbor(v),
|
||||||
Err(_) => Output::None,
|
Err(_) => Output::Fail,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +40,7 @@ where
|
||||||
{
|
{
|
||||||
match serde_pack::to_vec(val) {
|
match serde_pack::to_vec(val) {
|
||||||
Ok(v) => Output::Pack(v),
|
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.headers_mut().insert(CONTENT_TYPE, con);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
Output::None => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
Output::None => StatusCode::OK.into_response(),
|
||||||
|
Output::Fail => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue