diff --git a/httpret/src/lib.rs b/httpret/src/lib.rs index 4620425..74c886c 100644 --- a/httpret/src/lib.rs +++ b/httpret/src/lib.rs @@ -263,7 +263,7 @@ async fn binned(req: Request, node_config: &NodeConfigCached) -> Result binned_binary(query, node_config).await, Some(v) if v == "application/json" => binned_json(query, node_config).await, - _ => Err(Error::with_msg("binned with unknown accept")), + _ => Ok(response(StatusCode::NOT_ACCEPTABLE).body(Body::empty())?), } } diff --git a/httpret/src/search.rs b/httpret/src/search.rs index cbee714..f5fbcb5 100644 --- a/httpret/src/search.rs +++ b/httpret/src/search.rs @@ -1,12 +1,18 @@ +use crate::response; use err::Error; use hyper::{Body, Request, Response, StatusCode}; use netpod::{ChannelSearchQuery, NodeConfigCached}; pub async fn channel_search(req: Request, node_config: &NodeConfigCached) -> Result, Error> { let (head, _body) = req.into_parts(); - let query = ChannelSearchQuery::from_request(head.uri.query())?; - let res = dbconn::search::search_channel(query, node_config).await?; - let body = Body::from(serde_json::to_string(&res)?); - let ret = super::response(StatusCode::OK).body(body)?; - Ok(ret) + match head.headers.get("accept") { + Some(v) if v == "application/json" => { + let query = ChannelSearchQuery::from_request(head.uri.query())?; + let res = dbconn::search::search_channel(query, node_config).await?; + let body = Body::from(serde_json::to_string(&res)?); + let ret = super::response(StatusCode::OK).body(body)?; + Ok(ret) + } + _ => Ok(response(StatusCode::NOT_ACCEPTABLE).body(Body::empty())?), + } }