Documentation
use hyper::body::Bytes;
use hyper::{Response, StatusCode};

/// 错误回复
pub(crate) fn make_error_response(
    status: StatusCode,
    body_text: String,
    content_type: &str,
) -> Response<http_pool::body::VariantBody> {
    Response::builder()
        .status(status)
        .header("Content-Type", content_type)
        .header("Content-Length", body_text.len().to_string())
        .body(http_pool::body::variant_body(http_pool::body::Full::new(
            Bytes::from(body_text),
        )))
        .unwrap()
}

/// 目标地址不通
pub(crate) fn bad_gateway() -> Response<http_pool::body::VariantBody> {
    let body_text = format!("{}: {}", StatusCode::BAD_GATEWAY, "Target unreachable");
    make_error_response(
        StatusCode::BAD_GATEWAY,
        body_text,
        "text/plain; charset=utf-8",
    )
}