use http_pool::body::{VariantBody, variant_body};
use hyper::body::Bytes;
use hyper::{Response, StatusCode};
pub static TEXT_CONTENT_TYPE: &str = "text/plain; charset=utf-8";
pub static JSON_CONTENT_TYPE: &str = "application/json";
pub fn response<B: Into<String>>(
code: StatusCode,
body: Option<B>,
content_type: &str,
) -> Response<VariantBody> {
let builder = Response::builder()
.status(code)
.header("Content-Type", content_type);
if let Some(b) = body {
let b = b.into();
builder
.header("Content-Length", b.len().to_string())
.body(variant_body(http_pool::body::Full::new(Bytes::from(b))))
.unwrap()
} else {
builder.body(http_pool::body::empty()).unwrap()
}
}